Using Sub Class in C# programming


C# has many advance feature that make it more advance than more Programming Languages. Defining Sub class is one of them. ":" colon is used for reference sub class to base class.in this program i will show you using Sub Class in C# programming language

Sub Class in C#


In C# programming,we can declare subclass which derives methods and variable of a base class. subclass define by refernce of base class. ":" colon used in C# for reference subclass to base class. After declaring class,we need to define the variable and methods,which are separate from the variable and methods contained in the super class.
Given bellow code show you how to define Sub class in C#:

using System;
using System.Collections.Generic;
using System.Text;

namespace defineSubclass

{

class Base

{

public void baseDisplay()

{

Systemm.Console.WriteLine("Base Class Method");

}

class Derived : Base

{

void derivedDisplay()

{

System.Console.WriteLine("derived Class Method");

}

class mainPrograam

{

static void Main(string[] args)


{

derived obj= new Derived();

obj.basedisplay();

obj.deriveddisplay();

}
}
}
}
}


In this code derived class is sub class for the base class.In derived class a method,deriveddisplay,is defined and the Base class contain a method,basedisplay().First basedisplay() method of Base class is called and then deriveddisplay() method of derived class is called.
Out Put of this programming will be like as given below:
Base Class Method
Derived Class Method
Press any key to continue.....


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: