Implementing inheritance in C# is similar to implementing it in C++. You use a colon (:) in the definition of a class to derive it from another class.
In this example. i will create 3 class which are Class BaseClassA, BaseClassB, and Main Class which is myClass
Inheritance example
// Base class A class BaseClassA { publicvoid MethodA() { Console.WriteLine("A Method called"); } } // Base class B is derived from Base class A class BaseClassB : BaseClassA { public void MethodB() { Console.WriteLine("B method called"); } } // Main class class myClass { static void Main() { // Base class B BaseClassB b = newBaseClassB(); // Base class B method b.MethodB(); // BaseClassA Method through BaseClassB b.MethodA(); } }
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment