A reference variable of a superclass can be assigned a reference to any subclass derived from that superclass. In the following program, obj is a reference to NewData object, Since NewData is a subclass of Data, it is permissible to assign obj a reference to the NewData object. When a reference to a subclass object is assigned to a superclass reference variable, you will have access only to those parts of the object defined by the superclass. This is wayobj can’t access data3 and data4 even it refers to a NewData object.
Program
Program Source
No comments:
Post a Comment