There are 2 classes, 1 LandAnimal and another WaterAnimal.
There is another class Animal which wants to have the
properties of both LandAnimal and WaterAnimal. How will you
design this situation?

Answer Posted / bhaskr reddy

interface LandAnimals {

class LandAnimal {

// define the Land Animal prperties
}
}

interface WaterAnimals{

class WaterAnimal{

// define the Water Animal prperties
}
}

Now define the "Animal" class by implementing the two
interfaces(WaterAnimals and LandAnimals ).

Note1 : Java supports defining the class inside an
interface.

Note 2 : In the previous answer somebody has defined two
seperate classes for WaterAnimal and Land animal
and his LandAnimal extends WaterAnimal then LandAnmal
becomes the Water animal this is poor object orientation.

Is This Answer Correct ?    18 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is predicate in java?

556


what are the states associated in the thread? : Java thread

591


What is singletonlist in java?

503


What about abstract classes in java?

606


What is exception hierarchy in java?

583






Explain illegalmonitorstateexception and when it will be thrown?

616


Is overriding possible in java?

499


What is the difference between call by reference and call by pointer?

497


What do you understand by an io stream?

578


What is internal iteration in java se 8?

625


I want my class to be developed in such a way that no other class (even derived class) can create its objects. Define how can I do so?

689


Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.

1507


What are Normalization Rules? Define Normalization?

548


What technique can be employed to compare two strings?

569


What happens if an exception is throws from an object's constructor?

625