This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IS-A / HAS-A relationships. Chapter 2 Question 14 page 180 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IS-A / HAS-A relationships. Chapter 2 Question 14 page 180" Watch "IS-A / HAS-A relationships. Chapter 2 Question 14 page 180" New topic
Author

IS-A / HAS-A relationships. Chapter 2 Question 14 page 180

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

You're designing a new online board game in which Floozels are a type of Jammers, Jammers can have Quizels, Quizels are a type of Klakker, and Floozels can have severl Floozets. Which of the following fragments represent this design? (choose all that apply)

The correct answers are given as A and C.

A.

C.


Given that Floozels can have several Floozets, this implies that Floozet is an instance variable. A shows it as an interface and C shows it as an instance variable.

Looking forward to your help as always :-)

OCPJP 6, OCMJD
Joseph Arnold
Ranch Hand

Joined: Oct 05, 2010
Posts: 42
Floozel can have several Floozets mean there can be several instances of Floozets in floozel. Well, both options illustrate the same. Whether Floozet is a class type or an interface type does not matter. We must only ensure that there is some appropriate collection of floozets in a floozel.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
According to Effective Java by Josh Bloch, we should use interface to define object type. This is the only usage of interface. Therefore, while a class is to define type, an interface is also used for defining type.
In K&B book, use interface as if a 100% abstract class. 100% abstract class is the abstract class that only contains abstract methods. Interface contains all abstract method, too.

So, while we use class/abstract class to define type, we can also use interface to define type.

Correct me if I am wrong.
Alexander Shrago
Greenhorn

Joined: Aug 18, 2008
Posts: 14
I have a doubt about correct answers to Chapter 2 Question 14

What is Jammers, Quizels and so on? They are not strict names оf classes and interfaces but samples of real objects

So answer "D" is also correct inspite of authors opinion:

import java.util.*;
interface Jammer extends Quizel { }
interface Klakker { }
interface Quizel extends Klakker { }
interface Floozel extends Jammer, Floozet { }
interface Floozet { }

Checking it:
floozels are a type of Jammers - yes
quizels are a type of Klakker - yes
Jammers can have Quizels and Floozels can have several Floozets - Where do you see that they can not ??

Am I wrong?

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

try to understand IS-A and HAS-A relationships...
Alexander Shrago
Greenhorn

Joined: Aug 18, 2008
Posts: 14
Chapter 2 Question 14 is

"You’re designing a new online board game in which Floozels are a type of Jammers, Jammers can
have Quizels, Quizels are a type of Klakker, and Floozels can have several Floozets. Which of the
following fragments represent this design?"

I get that you mean, but
where are no words "IS-A" or "HAS-A"

"HAS-A" relationships can appear later during realization

Where am I wrong?


saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Alexander Shrago wrote:Chapter 2 Question 14 is

"You’re designing a new online board game in which Floozels are a type of Jammers, Jammers can
have Quizels, Quizels are a type of Klakker, and Floozels can have several Floozets. Which of the
following fragments represent this design?"

I get that you mean, but
where are no words "IS-A" or "HAS-A"

"HAS-A" relationships can appear later during realization

Where am I wrong?






Tell the difficulties that i am difficult.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Alexander Shrago wrote:

So answer "D" is also correct inspite of authors opinion:

import java.util.*;
interface Jammer extends Quizel { }
interface Klakker { }
interface Quizel extends Klakker { }
interface Floozel extends Jammer, Floozet { }
interface Floozet { }

Checking it:
floozels are a type of Jammers - yes
quizels are a type of Klakker - yes
Jammers can have Quizels and Floozels can have several Floozets - Where do you see that they can not ??

spot on! you got it there...
Alexander Shrago wrote:
Am I wrong?

yes...
Guilherme Bazilio
Greenhorn

Joined: Mar 02, 2009
Posts: 23


Java does not support multiple inheritance! So answer D is false!

Ted North
Ranch Hand

Joined: Jan 02, 2012
Posts: 192
    
    1

Glen Iris wrote:You're designing a new online board game in which Floozels are a type of Jammers, Jammers can have Quizels, Quizels are a type of Klakker, and Floozels can have severl Floozets. Which of the following fragments represent this design? (choose all that apply)

The correct answers are given as A and C.

A.

C.


Given that Floozels can have several Floozets, this implies that Floozet is an instance variable. A shows it as an interface and C shows it as an instance variable.

Looking forward to your help as always :-)


I made a UML diagram that may explain things:


With interfaces or classes the same IS-A/HAS-A relationships apply. If a class implements an interface then that class IS-A whatever that interface is. This is what is so handy-dandy about polymorphism. Plus a class can implement multiple interfaces while it can only extend one class. Interfaces normally are outside of the class hierarchy too and enable some sort of action.

For instance Dog extends Animal and Dog and and animal both implement the interface Eat. A java programmer can reuse the Eat interface for a class that pertains to Androids, Animals, or Humans.

I hope this made some sense to you. Keep reading about it and coding, you will understand in time Glen Iris.

Alexander Shrago
Greenhorn

Joined: Aug 18, 2008
Posts: 14
Guilherme Bazilio wrote:

Java does not support multiple inheritance! So answer D is false!



There are no problem for an interface to extend many interfaces. Check it!

-------------------
Sorry for all !!

I read the question inattentive - it is correctly formulated:
"Which of the following fragments represent this design?..."

The question is about the design representation, not about possibilities to have - so I am wrong about "D" ))

Guilherme Bazilio
Greenhorn

Joined: Mar 02, 2009
Posts: 23
Alexander Shrago wrote:
Guilherme Bazilio wrote:

Java does not support multiple inheritance! So answer D is false!



There are no problem for an interface to extend many interfaces. Check it!



You're totally right!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IS-A / HAS-A relationships. Chapter 2 Question 14 page 180
 
Similar Threads
E super CharSequence makes no sense??
instanceof
Casting
abstract method TimeZone.getRawOffset