File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes looking at this code, why Planet class is not a Star class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "looking at this code, why Planet class is not a Star class?" Watch "looking at this code, why Planet class is not a Star class?" New topic
Author

looking at this code, why Planet class is not a Star class?

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
looking at the code below, why does the explanation of the code say
"The use of inheritance in this code is not justifiable since, conceptually, a planet is-not-a star. "? but the class Planet extends class Star?
Thanks for your help.


[ September 14, 2004: Message edited by: Barry Gaunt ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

You are correct that in the code, planet does indeed extend star. but what they are saying is "this is bad - don't do this".

in the "real world", there is no way you could consider a planet to be a star. You would never say "the earth IS-A star" or "Jupiter IS-A star". So this code is not good OO practice. You can't justify doing this.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: looking at this code, why Planet class is not a Star class?
 
Similar Threads
why would this code run without an error?
Another question from Khalid
Help needed on Inheritance
is-a question
KAM India Edition Question 6.27