Inherit a Class (C#) : Class Inheritance « Language Basics « ASP.Net






Inherit a Class (C#)

<%@ Page Language="C#" %>
<script runat="server">

    public class Animal {
    
       private int legs;
       private string  bodyHair;
    
       public int Legs {
         get {
           return legs;
         }
         set {
           legs = value;
         }
       }
    
       public string  BodyHair {
         get {
           return bodyHair;
         }
         set {
           bodyHair = value;
         }
       }
    
       public string  Walk() {
         return "I'm walking on " + legs + " legs";
       }
    
    }
    
    public class Dog : Animal {
    
       public Dog() {
         Legs = 4;
       }
    
       public string  Bark() {
         return "Woof";
       }
    
       public string  Bite() {
         return "Chomp Chomp";
       }
    
       public string  Wag() {
         return "Wag Wag";
       }
    }
    
    public class Person : Animal {
    
       public Person() {
         Legs = 2;
       }
    
       public string  Talk() {
         return "yadda yadda yadda";
       }
    }
    
    void Page_Load(object Sender, EventArgs E) {
    
       Dog d = new Dog();
       Response.Write(d.Walk());
       Response.Write("<br />");
       Response.Write(d.Bark());
       Response.Write("<br />");
    
       Person  p = new Person();
       Response.Write(p.Walk());
    }

</script>
<html>
<head>
</head>
<body>
</body>
</html>

           
       








Related examples in the same category

1.Inherits class (VB.net)
2.Inherits class (C#)