c# - About instantiate a class from inherited class -


what difference between this

derivedclass classinst = new derivedclass(); 

and

baseclass classinst = new derivedclass(); 

i can't seem see difference , compiler doesn't complain, can use interchangeably?

the difference between 2 if

derivedclass classinst = new derivedclass();

the compiler interprets classinst derivedclass, , allows use specific methods/properties/etc have declared in derived class , not in base class.

on other hand, if baseclass classinst = new derivedclass();

the compiler interpret classinst baseclass, , not have access members.

do realize actual type of object not change. reference object stays same, no matter of 2 declarations use. thing changes how reference interpreted, , therefore members available; of base class, or derived class.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -