Answer to Question #326398 in C# for Chinara

Question #326398

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



1
Expert's answer
2022-04-11T14:01:19-0400
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();
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS