Monday, December 17, 2012

PROGRAM TO DEMONSTRATE INHERITANCE

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

namespace ConsoleApplication13
{
class A
{
int a, b, c;
public void show()
{
a = 10;
b = 15;
c=a+b;
Console .WriteLine ("Result of class A: "+c);
}
}
class B : A
{
public void display()
{
Console.WriteLine("We are in class B ");
}
}
class InheritanceDemo
{
static void Main(string[] args)
{
B obj = new B();
obj.show(); //accessing class A's function by B's object
obj.display();
Console.ReadLine();
}
}
}

<<<<<<<<<<<<<<<<<<<<<<< OUTPUT >>>>>>>>>>>>>>>>>>>>>>>

Result of class A: 25

We are in class B

No comments:

Post a Comment