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
What is predicate in java?
what are the states associated in the thread? : Java thread
What is singletonlist in java?
What about abstract classes in java?
What is exception hierarchy in java?
Explain illegalmonitorstateexception and when it will be thrown?
Is overriding possible in java?
What is the difference between call by reference and call by pointer?
What do you understand by an io stream?
What is internal iteration in java se 8?
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?
Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.
What are Normalization Rules? Define Normalization?
What technique can be employed to compare two strings?
What happens if an exception is throws from an object's constructor?