• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance, need help  RSS feed

 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me in solving this question ?? Please explain the concept how to check ??

Consider the following classes:


Thanks
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A super class reference variable can refer to a subclass instance but a subclass reference cannot point to a super class instance.

I will leave it for you to compile and check which leads to the issue and why.

This might help - http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html
 
Sagar Dabas
Ranch Hand
Posts: 47
C++ Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
" Any superclass reference variable can refer to the subclass object "

In this case...
this is the inheritance tree.

Vehicle----->Car----->Suv

Vehicle is the superclass of Car and Suv => 1 and 6 correct
Car is the superclass of Suv = > 5 correct
Suv is the subclass => So only 3 point is correct.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this campfire story:
http://www.javaranch.com/campfire/StoryPoly.jsp
 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!