Difference between var and Class class in object creation
- by Divine
Its a silly question, however shocked to see different behaviors. Learning a lot.
Lets say I have two classes below
Class A
{
public void Display()
{
}
}
Class B : A
{
public void Display()
{
}
}
Class C : B
{
public void Display()
{
}
}
Class Final
{
static void Main()
{
var c = new C();
// B c = new C();
//My doubt is, both of the above gives different results. May I know B c = new C() creates object of B or C? What I understood is, it creates object of B. Then why we say "new C()"? I agree with C c = new C(); But I thought, B b = new C(); creates object of B. Where we use this style? Only when utilizing runtime polymorphism? (Overriding methods)?
}
}