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 int and integer in java?
Can a top level class be private or protected?
What is method overloading and method overriding?
Which are the two subclasses under exception class?
Why does abstract class have constructor?
What is the difference between an object-oriented programming language and object-based programming language?
What are implicit objects in java?
How do you test a method for an exception using junit?
What are the restrictions that are applied to the java static methods?
What is the difference between member variables initialization and assignment in a constructor?
What is immutable data?
How to sort double array in java?
What is thread life cycle?
What is the driver class?
What is sorting algorithm in java?