Ads Here

Monday, August 15, 2011

What is Inheritance

When a class acquire the property of another class is known as inheritance.

Inheritance is process of object reusability.

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:

No comments: