Saturday, August 14, 2010

HAS-A: Fizzler.java

Courtesy of education.oracle.com

A programmer wants to develop an application in which Fizzlers are a kind of Whoosh, and Fizzlers also fulfill the contract of Oompahs. In addition, Whooshes are composed with several Wingits.

Which code represents this design?

a) 

class Wingit { }
class Fizzler extends Oompah implements Whoosh { }
interface Whoosh {
    Wingits [] w;
}
class Oompah { }
 
b)

class Wingit { }
class Fizzler extends Whoosh implements Oompah { }
class Whoosh {
    Wingits [] w;
}
interface Oompah { } 

c) 

class Fizzler { }
class Wingit extends Fizzler implements Oompah { }
class Whoosh {
    Wingits [] w;
}
interface Oompah { }

d) 

interface Wingit { }
class Fizzler extends Whoosh implements Wingit { }
class Wingit {
    Whoosh [] w;
}
class Whoosh { }
 

b is correct. 'Kind of' translates to extends, 'contract' translates to implements, and 'composed' translates to a has-a implementation.

No comments:

Post a Comment