using System;
public class Mammal
{
public int Age { get; set; }
public Mammal(int age)
{
this.Age = age;
}
public void Sleep()
{
Console.WriteLine("Shhh! I'm sleeping!");
}
}
using System;
public class Dog : Mammal
{
public string Breed { get; set; }
public Dog(int age, string breed) : base(age)
{
this.Breed = breed;
}
public void WagTail()
{
Console.WriteLine("Tail wagging...");
}
}
using System;
class SimpleInheritance
{
static void Main()
{
Dog joe = new Dog(8, "Labrador");
joe.Sleep();
joe.WagTail();
Console.WriteLine("Joe is {0} years old dog of breed {1}.",
joe.Age, joe.Breed);
Console.ReadLine();
}
}
OUTPUT
Shhh! I'm sleeping!
Tail wagging...
Joe is 8 years old dog of breed Labrador.
public class Mammal
{
public int Age { get; set; }
public Mammal(int age)
{
this.Age = age;
}
public void Sleep()
{
Console.WriteLine("Shhh! I'm sleeping!");
}
}
using System;
public class Dog : Mammal
{
public string Breed { get; set; }
public Dog(int age, string breed) : base(age)
{
this.Breed = breed;
}
public void WagTail()
{
Console.WriteLine("Tail wagging...");
}
}
using System;
class SimpleInheritance
{
static void Main()
{
Dog joe = new Dog(8, "Labrador");
joe.Sleep();
joe.WagTail();
Console.WriteLine("Joe is {0} years old dog of breed {1}.",
joe.Age, joe.Breed);
Console.ReadLine();
}
}
OUTPUT
Shhh! I'm sleeping!
Tail wagging...
Joe is 8 years old dog of breed Labrador.
No comments:
Post a Comment