Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace overrideAndNew
{
// Object Orianted Programing
// Override and New
// class mine
class parson
{
virtual public void msg()
{
Console.WriteLine("i am a parson");
}
}
// class inheritance
class programming : parson
{
// new mithod
public new void msg()
{
Console.WriteLine("i am programming");
}
}
// class inheritance
class doctor:parson
{
// Override mithod
public override void msg()
{
Console.WriteLine("i am a doctor");
}
}
// king class
class Program
{
static void Main(string[] args)
{
programming prog = new programming();
doctor doc = new doctor();
// Line One
Console.Write("Line One ");
parson mine = new programming();
mine.msg(); // this Write is Parson
// Line Tow
Console.Write("Line Tow ");
mine = new doctor();
mine.msg(); // this Write is Doctor
// Line Three
Console.Write("Line Three ");
parson test2 = new doctor();
test2.msg(); // this Write is Doctor
// Line Four
Console.Write("Line Four ");
test2 = new programming();
test2.msg(); // this Write is Parson
Console.ReadKey();
}
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more