• 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

... if code defines an is-a relationship

 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

maybe this is a foolish question, but I was really surprised about the answer in the Mughal/Rasmussen book (Q. 7.37):


This is the (EDIT) statement (formerly: answer) I am confused about:

(b) The code defines a Planet is-a Star relationship.


This statement is wrong according to the solution.
So guys (and girls). For this answer to be true it is not enough to have the class Planet to subclass the class Star? We need to have a reference value of type Star which references to a object of type Planet? Like the out commented part in the code?
I just want to be 100% sure.

Thanks
Bob
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a class has a reference to another class, it is HAS-A relationship. IS-A relationship is always defined by inheritance. So the book is correct...
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is also a way to increment the post counter: answering his own questions
That wasn't a foolish question. I was just too clever for this Mughal/Rasmusseen book.
I was right in the first place. Of course this code defines a Planet is-a Star relationship. But there was a BIG typo in the question and answer.
Here is his link to the Errata: Mughal's errata

cheers
Bob
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a class A extends other class B or implements an interface B then we say that "A Is-A B". That is enough. class A need not have reference of type B. If it has reference only then it becomes a Has-A relation. If a method of class A creates an object of class B or a method of class A invokes a method of class B then relation will be "A Uses-A B".

What would be the answer for this :-


class B "Is-A/Has-A or Uses-A" A?
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:When a class has a reference to another class, it is HAS-A relationship. IS-A relationship is always defined by inheritance. So the book is correct...


Thanks for your fast answer. I didn't quote my question good enough. I edited it now in my first post. This was the statement, which the solution negated to

The code defines NOT a Planet is-a Star relationship


But that was a type (my previous post).

cheers
Bob
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys. I was suddenly so insecure about that. I will never believe in other solutions only in myself

cheers
Bob
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm totally confused but anyway, the best thing is you got the concept ...
 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too am confused about what exactly is the final conclusion?

@Bob,
I feel what you are talking about refers to polymorphism.According to me the given is correct.


 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about all this confusion.
I try to state the question from the book again, regarding the code from post 1:


Which statements about the program [upper code] are true?
...
(b) The code defines a Planet is-a Star relationship.
...



I thought, yeah sure, BUT, and here came my confusion, the solution (from the book) said to me: NOPE this is wrong.
And I began to think ( ); always bad. After I've written my upper post I found the error list to the book (Errata Link).
So in the end, of course ( ) statement (b) is true.


@Bob,
I feel what you are talking about refers to polymorphism.According to me the given is correct.


Yep. That's right. Mughal/Rasmussen are wrong, we are right !!!

Sorry again about that confusion again
Bob
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic