20 Oct 2017

Inheritance - OOPS Programming

Inheritance: 

When a class acquire the property of another class is known as inheritance. Inheritance is process of object re-usability. For example, A Child acquire property of Parents.

public class ParentClass
    {
        public ParentClass()
        {
            Console.WriteLine("Parent Constructor.");
        }
        public void print()
        {
            Console.WriteLine("I'm a Parent Class.");
        }
    }
    public class ChildClass : ParentClass
    {
        public ChildClass()
        {
            Console.WriteLine("Child Constructor.");
        }
        public static void Main()
        {
            ChildClass child = new ChildClass();
            child.print();
        }
    }



Output:
    Parent Constructor.
    Child Constructor.
    I'm a Parent Class.

No comments:

Post a Comment