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
Is string a data type in java?
Which object oriented concept is achieved by using overloading and overriding?
Why vector class is used?
Have you ever used hashtable and dictionary?
What are strings in physics?
What are mutable classes?
What is unicode full form?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Can we extend singleton class?
What is java autoboxing?
Explain about varargs in java?
Can we override constructors?
What is concurrent hashmap and its features?
Explain JMS in detail.
What is jar?