• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dan's question - clarify!!!

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Leg{}
class Fur{}
abstract class Pet {
public abstract void eat();
public abstract void sleep();
}
class Dog extends Pet {
Leg leftFront = new Leg(), rightFront = new Leg();
Leg leftRear = new Leg(), rightRear = new Leg();
Fur fur = new Fur();
public Fur shed() {return fur;}
public void eat() {}
public void sleep() {}
}
class Cat extends Dog {
public void ignoreOwner() {}
public void climbTree() {}
}
Which of the following statements is not a true statement?
a. A Cat object inherits an instance of Fur and four instances of Leg from the Dog superclass.
b. A Cat object is able to sleep and eat.
c. A Cat object is able to climb a tree.
d. The relationship between Dog and Pet is an example of an appropriate use of inheritance.
e. The relationship between Cat and Dog is an example of an appropriate use of inheritance.
f. None of the above.
I thought F but,
answer given is E....saying "The relationship between the Cat subclass and the Dog superclass is not an example of an appropriate use of inheritance, because a Cat is not a Dog. "
Clarify !!
~ Shalini
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taurean,
An appropriate use of inheritance implements an "is-a" relationship. A Dog is-a Pet; so it is appropriate to implement an inheritance relationship between Pet and Dog. A Cat is not a special case of a Dog; so an inheritance relationship between Dog and Cat is not appropriate. For example, suppose that somebody implements a herdSheep method in the Dog class. The Cat subclass would inherit the method and enable an instance of Cat to herd sheep. It is difficult to imagine a Cat performing well in that role.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan,
If a question of this sort is asked in the exam, should we take the common sense approach to the problem or go by the way the question was framed by using the OOPS/Java concepts irrespective of it being completely opposite to the real world situation.
Thank you very much,
Rama
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rama,
The SCJP objectives state the following.


State the benefits of encapsulation in object oriented design and write code that implements tightly encapsulated classes and the relationships "is a" and "has a".


On the real exam, I recall there were questions that implement "is-a" and "has-a" relationships and the questions ask which relationships are examples of "is-a" and which are examples of "has-a". I don't recall any questions that were designed to determine if you really understand the appropriate use of each kind of relationship. I suppose that concept may have been deferred to the developer exam.
From my point of view, if you're going to test if a person is able to recognize a relationship, then it makes sense to determine if the person has a basic understanding of the appropriate use of the relationship. If the usage of the relationships is not understood, then what is gained by recognizing the relationships?
This question might be slightly beyond the scope of what is likely to appear on the real exam, but it certainly is not beyond the scope of what every employer will expect each programmer to understand.
reply
    Bookmark Topic Watch Topic
  • New Topic