Here is an example of the new keyword in C Sharp:
Code:
public class Parent
{
public virtual void temp()
{
.
.
.
}
}
public class Child : Parent
{
public new void temp()
{
.
.
.
}
}
.
.
.
Parent p = new Child();
Child c = new Child();
p.temp();
c.temp();
This is the program for override keyword in C Sharp:
Code:
public class Parent
{
public virtual void temp()
{
.
.
.
}
}
public class child : Parent
{
public override void temp()
{
.
.
.
}
}
.
.
.
Parent p = new child();
p.temp();
This topic is all related to the polymorphism concept of C Sharp. In a scenario where the programmer does not provides the override or new keywords the throughput is as if the programmer made use of the new keyword. But the compiler us expected to generate a compile time error.
Bookmarks