Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is-a Relation Question

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following code, which statements are true?


Options
a. Class B implements interface A.
b. Class B is-a A.
c. class B has-a A


Question: Whether option "b" is correct.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm.. vishnu! I would like to know from where did you get the question? Hope you are not trying to replicate the following thread...

http://www.coderanch.com/t/249665/java-programmer-SCJP/certification/Implementing-interface-it
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The notion of IS-A is independent of Java. Java types that extend a class or implement an interface have an IS-A relationship with the class or interface. If you implement Duck you're a duck; if you extend Duck you're a Duck. Simple.
 
Todd Farmer
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rick O'Shay:
The notion of IS-A is independent of Java. Java types that extend a class or implement an interface have an IS-A relationship with the class or interface. If you implement Duck you're a duck; if you extend Duck you're a Duck. Simple.


In code, this would look like this:




It doesn't matter whether A is an interface that B implements, or whether B is a subclass of A. Regardless, B does eveything that an A can, so B is an A.

Todd Farmer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic