• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can a super class hold a reference to its child class  RSS feed

 
Suman Mummaneni
Ranch Hand
Posts: 97
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Need a quick clarification, can a super class hold a reference to its child class like its going to have Is A and Has A relations. Example below



I saw simillar code in java.util.Calender, Its returning a GregorianCalender a sub class of Calender.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving you to somewhere where you will get more attention.

Have you tried it? Can you think of any reason why such code would go wrong? Is there going to be any different between a subclass and any other class in terms of type for a field?
Have you been taught to say parent and child; those terms don't adequately represent inheritance in the computer sense of the world. It is better to say superclass and subclass (or maybe what they say in C#: base and derived classes).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!