Java Reference
In-Depth Information
2. Model part of an animal hierarchy by declaring Animal , Bird , Fish ,
AmericanRobin , DomesticCanary , RainbowTrout , and Sock-
eyeSalmon classes:
Animal is public and abstract , declares private String -based
kind and appearance fields,declaresa public constructorthatinitial-
izesthesefieldstopassed-inarguments,declares public and abstract
eat() and move() methodsthattakenoargumentsandwhosereturntype
is void ,andoverridesthe toString() methodtooutputthecontentsof
kind and appearance .
Bird is public and abstract , extends Animal , declares a public
constructor that passes its kind and appearance parameter values to
its superclass constructor, overrides its eat() method to output eats
seeds and insects (via System.out.println() ),andoverrides
the move() method to output flies through the air .
Fish is public and abstract , extends Animal , declares a public
constructor that passes its kind and appearance parameter values to
its superclass constructor, overrides its eat() method to output eats
krill, algae, and insects ,andoverridesits move() methodto
output swims through the water .
AmericanRobin is public ,extends Bird ,anddeclaresa public noar-
gumentconstructorthatpasses "americanrobin" and "red breast"
to its superclass constructor.
DomesticCanary is public , extends Bird , and declares a public
noargumentconstructorthatpasses "domesticcanary" and "yellow,
orange, black, brown, white, red" toitssuperclassconstruct-
or.
RainbowTrout is public , extends Fish , and declares a public noar-
gument constructor that passes "rainbowtrout" and "bands of
brilliant speckled multicolored stripes running
nearly the whole length of its body" toitssuperclasscon-
structor.
SockeyeSalmon is public ,extends Fish ,anddeclaresa public noar-
gument constructor that passes "sockeyesalmon" and "bright red
with a green head" to its superclass constructor.
Search WWH ::




Custom Search