This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IS-A between class and interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IS-A between class and interface" Watch "IS-A between class and interface" New topic
Author

IS-A between class and interface

Jani Joeli
Greenhorn

Joined: Mar 21, 2007
Posts: 2
Hi to all!

I did the mock exam from LearnKey SCJP5 study guide CD (u know, the one that came with the excellent S&B book), and there was a question about IS-A relationships. One of the options was "IS-A relationships always require at least two class types", which was marked as correct.

I got a bit confused there: if a class implements an interface (ie. Ball implements Bounceable), then it can be said that "Ball IS-A Bounceable", right? In that case, is an interface considered to be a special kind of class to fulfil the "atleast two class types" rule?

Please correct me if I'm completely lost. Thanks for any help!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jani Joeli:
...if a class implements an interface (ie. Ball implements Bounceable), then it can be said that "Ball IS-A Bounceable", right? In that case, is an interface considered to be a special kind of class to fulfil the "atleast two class types" rule? ...

Welcome to JavaRanch!

An interface is not really a "special kind of class," but it is a type. So I might remove the word "class" from that rule to simply say, "at least two types."

On the other hand, maybe that's not quite right either. Isn't it accurate to say a Ball IS-A Ball? (Then again, if we're talking about "IS-A" in terms of polymorphism, then we wouldn't have much "poly" if there's only one type involved.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
maddy saddy
Greenhorn

Joined: Mar 13, 2007
Posts: 5
Yes Jani IS-A relationships always require at least two class types.

class B
{
....
}
class A extends B
{
....
}
Now you see IS-A relationships always require at least two class types.
class A extends B means class A is of type class B or class A is class B.
IS-A relationship works only with inheritence(A extends B) and implementation(interfaces).

I hope this will clear your doubt.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by maddy saddy:
...IS-A relationship works only with inheritence(A extends B) and implementation(interfaces)...

But this is the original poster's point: An interface is not a class, so how can you say IS-A always requires two classes?
Tor Henning Post
Greenhorn

Joined: Nov 14, 2003
Posts: 11
I agree with marc. And look at the question formulation "class type"

If you have a class "Horse" that implements the interface "Animal"
Then the Horse IS A animal.
Jani Joeli
Greenhorn

Joined: Mar 21, 2007
Posts: 2
Originally posted by marc weber:

But this is the original poster's point: An interface is not a class, so how can you say IS-A always requires two classes?


Conclusion: the option "IS-A relationships always require at least two class types" should be marked incorrect if similar question comes up in the real exam? I just want to make this clear to myself so when doing the exam, I won't screw up one of the easy ones..

Thanks very much for help!
Tor Henning Post
Greenhorn

Joined: Nov 14, 2003
Posts: 11
No, the statement is correct. There is a difference between class and class types. When you implement an interface you get a IS-A relationship to the class type that the interface represents.

See my previous post about the horsi
Jeremia Morling
Greenhorn

Joined: Sep 04, 2012
Posts: 1
Just to clarify for future students (found the same in certfication exam for Java 6). I think what Tor was saying is that the key lies in the question:
"When considering relationships between classes, which statement(s) are true? (Choose all that apply.)"
You are asked to only look at relationships between classes, not between classes and interfaces or between types.
In that case it makes sense that "is-a relationships always rely on inheritance", because we are not talkting about interfaces.

Stupid formulation of question/answer really!!
 
 
subject: IS-A between class and interface
 
Similar Threads
Polymorphic behavior provided by inheritance programming assignment
K&B page no 121 doubt
interface error
HAS-A relationship
SCJP for Java 6 book by Sierra and Bates covariant return code example question