Difference between var and Class class in object creation
Posted
by
Divine
on Stack Overflow
See other posts from Stack Overflow
or by Divine
Published on 2013-11-10T15:48:20Z
Indexed on
2013/11/10
15:53 UTC
Read the original article
Hit count: 195
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)?
}
}
© Stack Overflow or respective owner