Category >
CSHARP
|| Published on :
Friday, November 13, 2020 || Views:
614
||
inherit base class into derived class (no method overriding)
Here Pawan Kumar will explain how to inherit base class into derived class (no method overriding)
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication16
{
class A
{
public void Say()
{
Console.WriteLine("say A");
}
public void Write()
{
Console.WriteLine("write A");
}
}
class B : A
{
public void Say()
{
Console.WriteLine("say B");
}
public void Call()
{
Console.WriteLine("Call B");
}
}
class Demo
{
static void Main(string[] args)
{
A a = new A();
Console.WriteLine("India");
a.Say();
a.Write();
//a.call(); // call() not accessible by A's abject
Console.WriteLine("*USA");
B b = new B();
b.Say();
b.Write();
b.Call();
Console.WriteLine("--when (a=b)--");
a = b;
a.Say();
a.Write();
// a.Call(); // we cant call call() bcozz it is not defined by A class
Console.ReadLine();
}
}
}