About Question enthuware.ocpjp.v7.2.1248 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question enthuware.ocpjp.v7.2.1248 :

Post by ETS User »

Hello, part of question is:

Code: Select all

class Ting { String tang; } 
Yet the answer "Ting has-a String" is not marked as corrent.

From what i've seen so far, the questions concerning relation between classes are not focused on variable names. For example:

Code: Select all

public class Car  
{  
   private Engine motor;  
}  
we say that Car has-a Engine, not that Car has-a motor...
(http://www.coderanch.com/t/412062/java/ ... lationship)

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by admin »

I don't agree with it. Consider this:

class Person{
Person brother;
Person sister;
}

Person has a brother and a sister, which are of types Person.

HTH,
Paul.

RobynBackhouse
Posts: 23
Joined: Sun Apr 14, 2013 10:37 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by RobynBackhouse »

I have the same query I guess..

In other examples of HAS-A relationships, you can use the library example:

Code: Select all

Class Library{
    Book b = new Book();
    Book _$$_ = new Book();
} 
So in this case (according to your Toon has-a tang example) you would say the library has-a b and also the library has-a _$$_ ? That sounds very odd, as the variable name can be anything - even something totally meaningless, like b or _$$_ .

I would have thought you should say the library has-a Book..?

This is obviously an important concept, and I want to be sure I fully understand it.

Thanks for any advice you can give.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by admin »

Actually, no. A variable name should not be anything. Would you name a class that represents a Book as X? You could claim that it has all the fields an properties that are required for a book but you want to call it X. Of course, it is technically possible but not appropriate. Similarly, the attributes of a class are also named appropriately. You shouldn't name then a _$$_ even if that is technically possible.


BTW, your Library has only two books :) It would be more appropriate if you do:
class Library{
Book[] books;
}

HTH,
Paul.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by admin »

Another thing. The name of the class Book is not as important as the variable name book(s) in determining the relationship because Book could be an abstract class or a base class and you might want to assign a subclass such as HardCoverBook or AudioBook to book variable.

-Paul.

roccapl
Posts: 2
Joined: Wed May 22, 2013 10:37 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by roccapl »

I find very mixed results regarding the "has-a" relationship.
Could you point me to some respectable source (a book would be better) in which it is very clear that is not correct to say, for example, that a HumanBody has-an Organ named heart and has-an Organ named brain?

It seems a very subtle difference to me...

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by admin »

I don't think there is a subtle difference. I think there is a very clear difference. It really depends on how you are modeling the relationships. If you have an Organ class, then heart is the variable name. But if you have Heart as a class, then variable name doesn't matter. It is up to you how to model your domain.

I am afraid it will not be possible for me to give you any "respectable" reference. Books have errors too. So just because something is in a book doesn't make it respectable and just something is in a mock exam doesn't make it less respectable. You may post on other forums and get an answer that you would like to hear :)

-Paul

arthoor
Posts: 3
Joined: Thu Jul 04, 2013 11:19 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by arthoor »

Just got into this question, and I can't agree that it's correct. "Is-a" and "has-a" are just another words to talk about inheritance and composition (and these are the concepts tested by Oracle on the exam). In this context, as well as in any other high-level concept, variable names are completely irrelevant. Otherwise, changing name of a variable would affect system's architecture...
Sad to say, but this is a very misleading question, explanations in this thread make things even worse, both "incorrect" answers are actually correct, and the "correct" answer "Toon has-a tang" IS-A plain nonsense ;)

As for the reference, you might wish to consult Sharma&Ganesh "OCP SE7" or Sierra&Bates "SCJP for Java 6". Please suggest amendments for the upcoming Java 7 edition of the latter if you still think you got it right, or let the World have it's 5 minutes and just fix/remove this question ;)

Cheers,
Art

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1248 :

Post by admin »

This has now been fixed.

thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests