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
Post a Comment