Inheritance
Acquiring the properties of an existing class into a new class by establishing a parent–child relationship between classes is known as Inheritance.
The big advantage of inheritance is reusability of code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InheritanceDemo { class Parent { public void ParentMethod() { Console.WriteLine("this is parent method"); } } class child :Parent {
public void childmethod() { Console.WriteLine("this is child method"); } static void Main(string[] args) {
child obj = new child();
obj.childmethod(); obj.ParentMethod(); Console.ReadKey(); } } }
Acquiring the properties of an existing class into a new class by establishing a parent–child relationship between classes is known as Inheritance.
The big advantage of inheritance is reusability of code:
0 comments:
Post a Comment