• 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

Has-A relations must be on the same inheritance hiearchy

 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the k&B Practice Exams.






Answer (for Objective 5.5):
 B, E, and F are correct statements about the code.
 A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.
D is similarly incorrect because MyApp doesn’t “have” a Mungeable as part of its state.



When answering the above question i selected the option that says MyApp has-a Employee.
The book says that this is wrong because Employee and MyApp are not on the same inheritance tree. Is this correct?

I was not aware that the classes are supposed to be on the same inheritance tree for a has-a relationship.

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you print the actual question and all possible answers please?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HAS-A indicates that the class contains some reference at the instance level.
In the example- Employee is a local variable used in public static void main. Its not really part of MyApp class.
And HAS-A doesnt depend on the inheritance hierarchy- because its composition.

Which is the source you are using for this question and solution?
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:Can you print the actual question and all possible answers please?



I have updated the question.
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Sanaulla wrote:HAS-A indicates that the class contains some reference at the instance level.
In the example- Employee is a local variable used in public static void main. Its not really part of MyApp class.
And HAS-A doesnt depend on the inheritance hierarchy- because its composition.

Which is the source you are using for this question and solution?



It was a question from the K&B practice exams. The description given for the answer is

Answer (for Objective 5.5):
 B, E, and F are correct statements about the code.
 A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.
D is similarly incorrect because MyApp doesn’t “have” a Mungeable as part of its state.






 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

O. Ziggy wrote: A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.



I think you are confused with this statement right?

The statement above is stating the reasons why A and C are incorrect. The- "the MyApp class “uses” the Employee class, but MyApp isn’t in Employee’s class hierarchy" is justification for A not being correct and the other statement is a justification for C not being correct.
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Totally agree Mohamed.
 
Ranch Hand
Posts: 99
Mac Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not clear how "E. The code is loosely coupled." is a correct answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic