Create a class with a function that prints "This is parent class" and its subclass with another function that prints "This is child class". Now, create an object for each class and call
1 - function of the parent class by the object of the parent class
2 - function of the child class by the object of the child class c#
3 - function of the parent class by the object of the child class
class A
{
public void Print()
{
Console.WriteLine("This is parent class");
}
}
class B : A
{
public void Print()
{
Console.WriteLine("This is child class");
}
}
internal class Program
{
static void Main()
{
A a = new A();
B b = new B();
A ab = new B();
a.Print();
b.Print();
ab.Print();
Console.ReadKey();
}
}
Comments
Leave a comment