Ajay Gandhi
Why base class instance can not be stored in derived class reference? Or Why it is not possible to instantiate the base class instance in derived class variable?
By Ajay Gandhi in C# on Aug 24 2015
  • Komara Reddy
    Oct, 2016 13

    reference variable of parent class can point to object of the derived class but vice verse is not possible,because the derived class contains all members of parent class, but parent class not contain all member of child class, it make sense

    • 2
  • Sandeep Singh
    Sep, 2016 5

    Just like the variable of a class can be initialize by using instance of the same class , Same as Parent class variable can be initialize by using it's child class child class instance to make it reference class_child Cc = new class_child(); class_parent Pc = Cc; in the above case Pc is a Parent class reference that is created by using child class instance so Both Pc and Cc will be consuming or Accessing the same Object memory. Even if the Parent reference is consuming it's child class object memory by using Parent reference we Can't call any child class member that is "Purely define under the child class".

    • 0
  • Ajay Gandhi
    Apr, 2016 7

    Expecting Architect level answer

    • 0
  • Sunil Babu
    Apr, 2016 2

    It breaks the concept of OOPS Inheritance .

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS