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 / sahaj
[note:landanimal and wateranimal both behave as base class
and the other one behave as derieved class]
#include<iostream.h>
#include<conio.h>
class landanimal
{
void print();
{
cout<<"this is base class"<<endl;
}};
class wateranimal
{
void display();
{
cout<<"this is another base class"<<endl:
}};
class animal:public landanimal,public wateranimal
{
void disp();
{
cout<<"this is derieved class"<<endl;
}};
void main()
{
animal a;
a.print();
a.display();
a.disp();
getch();
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Explain the inheritance?
How do you do descending order in java?
Can subclass overriding method declare an exception if parent class method doesn't throw an exception?
What are serialization and deserialization?
Which is the class in java?
What is the primitive type short?
What is a JAR file?
Is there any sort function in java?
what do you understand by synchronization? Or what is synchronization and why is it important? Or describe synchronization in respect to multithreading? Or what is synchronization? : Java thread
What do you mean by thread safe?
List the features of java programming language.
How do I find and replace in word?
How to find the index of the largest number in an arraylist java?
Can we have this () and super () together?
How can u increase the heap size in the memory?