0% found this document useful (0 votes)
18 views8 pages

Practical 8

The document presents four C++ programs demonstrating different types of inheritance: single inheritance with a Dog class inheriting from an Animal class, multiple inheritance with a Bat class inheriting from both Mammal and WingedAnimal classes, multilevel inheritance with classes A, B, and C, and hierarchical inheritance with Dog and Cat classes inheriting from an Animal class. Each program includes code snippets and expected outputs. The aim is to illustrate the concepts of inheritance in object-oriented programming.

Uploaded by

Ahlam Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

Practical 8

The document presents four C++ programs demonstrating different types of inheritance: single inheritance with a Dog class inheriting from an Animal class, multiple inheritance with a Bat class inheriting from both Mammal and WingedAnimal classes, multilevel inheritance with classes A, B, and C, and hierarchical inheritance with Dog and Cat classes inheriting from an Animal class. Each program includes code snippets and expected outputs. The aim is to illustrate the concepts of inheritance in object-oriented programming.

Uploaded by

Ahlam Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PRACTICAL NO:8

Name:-Yash Amit Gadade Roll No:-28

Class:-FYIT Sub:-Object oriented programming Date:

Aim:- a) Write a C++ program that a illustrate single inheritance.

Code:-

#include<iostream>

using namespace std;

class animal

public:

void eat()

cout<<"I can eat!" <<endl;

void sleep()

cout<<"I can sleep!" <<endl;

};
class Dog:public animal

public:

void bark()

cout<<"I am bark!woof woof!!" <<endl;

};

int main()

Dog dog1;

dog1.eat();

dog1.sleep();

dog1.bark();

return 0;

OUTPUT:-
b) Write a C++ program that a illustrate multiple inheritance.

Code:-

#include<iostream>

using namespace std;

class mammal

public:

mammal()

cout <<"mammals can give direct birth"<<endl;

};

class wingedAnimal

public:

wingedAnimal()

cout<<"winged animal can flap"<<endl;

};

class Bat:public mammal,public


wingedAnimal{};

int main()

Bat b1;

return 0;

OUTPUT:-

c) Write a C++ program that a illustrate multilevel inheritance.

Code:-

#include<iostream>

using namespace std;

class A

public:

void display()

cout<<"Base class content.";


}

};

class B:public A{};

class C:public B{};

int main()

C obj;

obj.display();

return 0;

OUTPUT:-

D) Write a C++ program that a illustrate Hierarchical inheritance.

Code:

#include <iostream>

using namespace std;


class Animal

public:

void info()

cout << "I am an animal." << endl;

};

class Dog : public Animal

public:

void bark()

cout << "I am a Dog. Woof woof." << endl;

};

class Cat : public Animal

public:

void meow()

cout << "I am a Cat. Meow." << endl;


}

};

int main()

Dog dog1;

cout << "Dog Class:" << endl;

dog1.info();

dog1.bark();

Cat cat1;

cout << "¥nCat Class:" << endl;

cat1.info();

cat1.meow();

return 0;

Output:

You might also like