Wednesday, 6 April 2016

What is a base class and derived class?

A class is a template for creating an object. The class from which other classes derive fundamental
functionality is called a base class.
The class which derives functionality from a base class is called a derived class.

For e.g.
public class X
{
    private int a, b;

    public X()  // constructor
    {
        a = 0;
        b = 0;
    }

    public int A
    {
        get { return a; }
        set { a = value; }
    }

    public int B
    {
        get { return b; }
        set { b = value; }
    }
}
public class Y : X
{
    private System.Drawing.Color screenColor;

    public Y()  // constructor
    {
        screenColor = System.Drawing.Color.Red;
    }

    public System.Drawing.Color ScreenColor
    {
        get { return screenColor; }
        set { screenColor = value; }
    }
}
In above example Class Y derives from Class X, then Class X is a base class and Class Y is the derived class.

No comments:

Post a Comment

Featured post

What is SharePoint?

Microsoft SharePoint is an extensible platform that provides a range of products that can help organizations with solution for a variety...