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


Please Help Members By Posting Answers For Below Questions

What is the difference between int and integer in java?

519


Can a top level class be private or protected?

578


What is method overloading and method overriding?

538


Which are the two subclasses under exception class?

531


Why does abstract class have constructor?

565






What is the difference between an object-oriented programming language and object-based programming language?

578


What are implicit objects in java?

553


How do you test a method for an exception using junit?

540


What are the restrictions that are applied to the java static methods?

534


What is the difference between member variables initialization and assignment in a constructor?

669


What is immutable data?

585


How to sort double array in java?

593


What is thread life cycle?

544


What is the driver class?

569


What is sorting algorithm in java?

527