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
What is the difference between a loader and a compiler?
What is the use of accept () method in java?
What is adapter in java?
Explain the Propertie sof class?
When should the method invokelater() be used?
Can we pass null as argument in java?
How many ways can we create the string object?
Explain the importance of throwable class and its methods?
what do you mean by java annotations?
What is the length of a string?
What is the difference between superclass and subclass?
Does java isempty check for null?
Print Vertical traversal of a Binary Tree.
What is boolean keyword in java?
What is nullpointerexception in java?