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 do you mean by composition in java?
What will be the initial value of an object reference which is defined as an instance variable?
Can you explain the private protected field modifier?
What do you understand by the term polymorphism?
How do you create an array in java?
What does I ++ mean?
Why chararray() is preferred over string to store the password?
Is array size fixed in java?
What is an object in java?
How do you execute a thread in java?
What are latest features introduced with java 8?
Are arrays dynamic in java?
Explain about collection interface in java?
What is object-oriented paradigm?
How many types of literals are there in JAVA?