About Question enthuware.ocpjp.v7.2.1248 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

About Question enthuware.ocpjp.v7.2.1248 :

Post by The_Nick »

Hi everyone,
Are you sure it's not testing the design view of the thing?
If a class has a list of object, for example:
public class A{
String a= "string";
List<B> listB = new List<>();
}
class B{
}
Design speaking in terms of checking coupling.. does not make sense saying A has a list, whereas it's not correct saying that A has NOT a B since it will have many B potentially.
Also class A has-a String in terms of class design does not make much sense to me.
Do you have a reference asserting these kind of statements?

Thanks in advance.

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 am not sure I understand your question correctly. Could you please be a little more clear so that I can help?

thank you,
Paul.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

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

Post by The_Nick »

admin wrote:I am not sure I understand your question correctly. Could you please be a little more clear so that I can help?

thank you,
Paul.

Code: Select all

Class A
{
String name =""; 
List<B> list =new ArrayList<>();
}
Class B
{

}
2 points quite straight forward considering the above code:

1) A has a B because it's going to be a list of B, therefore the relation has-a. Instead you say that A has-a list.. which would not be compliant with an Object Oriented Design way to see these relationship.

2) Class A has-a String does not make sense to me. If the scope of the relationship is creating a Object Oriented Design relation has-a. The fact that a class has-a String is certainly true but not critical in terms of coupling.

Furthermore in this http://www.coderanch.com/t/616942/java- ... ation/OCJP link I got confirmed by another user that there is a has-a relationship between the List generic element and the class containing it.

Basically I would like to know why List<B> list = new ArrayList<>(): would not create a has-a relationship A has a B.

Thanks in advance.
Always available for further clarification about the question.

The_Nick.

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 »

There have been several discussions on this issue. The general consensus is that has-a relationship is based on the type of the variable and not the name of the variable.

I personally do not agree with that and have explained my reasons here: viewtopic.php?f=38&t=1677&hilit=ting

However, it is difficult to argue when someone says it is correct because it is written in a book (irrespective of who wrote it and why). So we decided to go with the consensus and avoid the confusion.

HTH,
Paul.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

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

Post by The_Nick »

Ok for the variable type vs variable name.
What about List<Bla> blaList;..

the link above mentioned (in the previous post) Blon has-a List of Blas

You are saying that "Blon has-a List of Blas." and not that Blon has-a Blas.. is there any documentation available supporting this concept? Coupling speaking it does create a relation with the 2 classes.
It is certainly true that Blon has a list of Blas, and as a consequence Blon has a/or many Blas..

What's your view on it?

Thanks in advance.

The_Nick.

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 »

Since it has many blas, by extension you could say that it has-a bla and it would be difficult to disagree with that from a purely logical perspective.

My personal opinion is that having having a List of Blas changes the relationship from an OO perspective. I don't consider having multiple as same as has-a. I don't consider List<Bla> same as Bla.

I would suggest you to get other opinions from folks at JavaRanch.

HTH,
Paul.

Student
Posts: 53
Joined: Fri Sep 20, 2013 7:20 am
Contact:

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

Post by Student »

I answered that "Blon has a Bla", having gone through K+B's OCP6 books.

According to Bates and Sierra:
"The phrase translations are “can have” usually means a class has an instance variable, or set of variables" (OCP SE6 Practice Exams, Ch7 Practice Exam 4 Question 56 (Answer)).

Yours unhappily,
Student :(

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 »

Please see the discussion above. Can't comment on what other books say.

HTH,
Paul.

SepticInsect
Posts: 20
Joined: Tue Nov 04, 2014 1:13 am
Contact:

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

Post by SepticInsect »

Why is alternative 2 incorrect?

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 »

SepticInsect wrote:Why is alternative 2 incorrect?
Because Toon doesn't have an instance variable of type tang. tang is a variable name in Ting. It is not a type. For has-a, the type of the variable is important not the name of the variable.

evafang2008
Posts: 9
Joined: Fri Jun 26, 2015 11:15 am
Contact:

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

Post by evafang2008 »

I can not understand why B is incorrect? "Toon has-a tang". I think it is correct. Could you please help me clear this?

I compared to Oracle Java SE 7 exam example #2:
http://education.oracle.com/pls/web_pro ... =SQ1Z0_804

2. Given:

class Class1 {
String v1;
}
class Class2 {
Class1 c1;
String v2;
}
public class Class3 {
Class2 c1;
String i3;
}

Which three options correctly describe the relationship between the classes?
A) Class2 has-a i3
B) Class1 has-a v2
C) Class2 has-a v2
D) Class3 has-a v1
E) Class2 has-a Class3
F) Class2 has-a Class1


The correct answer is CDF, the option C and D are similar to this question, why they are correct?
Thank you.

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 »

Please go through the discussion above.

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

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

Post by horst1a »

Sorry, i dont understand this.

Why is answer 1 right ? It shoud say Ting has a tang

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 »

Logically, you are right but there is no consensus on whether the has-a relationship is on the name or the type. As per the reports we have received from exam takers, the questions in the exam consider the relationship to be on the type instead of the name of the variable.


HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests