0% found this document useful (0 votes)
2 views5 pages

Lab 8 - Oop

This document outlines an experiment for a course on Object Oriented Programming, focusing on writing a C++ program to demonstrate multiple inheritance using Employee, Basic Info, and Department Info classes. It explains key concepts of inheritance, including base and derived classes, access control, and types of inheritance. The document also includes a sample code and its output, along with references for further reading.

Uploaded by

pranav duse
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)
2 views5 pages

Lab 8 - Oop

This document outlines an experiment for a course on Object Oriented Programming, focusing on writing a C++ program to demonstrate multiple inheritance using Employee, Basic Info, and Department Info classes. It explains key concepts of inheritance, including base and derived classes, access control, and types of inheritance. The document also includes a sample code and its output, along with references for further reading.

Uploaded by

pranav duse
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/ 5

Object Oriented Programming SE ECE SEM-II

Progressive Education Society’s


Modern College of Engineering
Department of Electronics and Telecommunication Engineering
Electronics and Computer Engineering Program
ACADEMIC YEAR: Class: S.E. Semester- II
Course: Object Oriented Programming

Experiment No 8

TITLE: Write a program in C++ to Read and Display the information of Employee Using Multiple Inheritance.
Use Basic Info and Department Info as a base classes of Employee class.

OBJECTIVES OF THE EXPT.:


The objective of this assignment is to teach the concepts of multiple inheritance.

APPARATUS: Computer with Windows Operating System.


CODE BLOCK or Eclipse IDE (Neon 3).

THEORY:

Inheritance:
 One of the most important concepts in object-oriented programming is that of inheritance.
 Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an
application. This also provides an opportunity to reuse the code functionality and fast implementation time.
 When creating a class, instead of writing completely new data members and member functions, the programmer
can designate that the new class should inherit the members of an existing class. This existing class is called the
base class, and the new class is referred to as the derived class.
 The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog IS-A mammal
hence dog IS-A animal as well and so on.

Base & Derived Classes:

 A class can be derived from more than one classes, which means it can inherit data and functions from multiple
base classes.
 To define a derived class, we use a class derivation list to specify the base class(es). A class derivation list
names one or more base classes and has the form:
class derived-class: access-specifier base-class
{
Class body;
};
 Where access-specifier is one of public, protected, or private, and base-class is the name of a previously defined
class. If the access-specifier is not used, then it is private by default. 
Access Control and Inheritance:

 A derived class can access all the non-private members of its base class. Thus base-class members that should
not be accessible to the member functions of derived classes should be declared private in the base class. 

MCOE, PUNE Page 1


Object Oriented Programming SE ECE SEM-II

 We can summarize the different access types according to - who can access them, in the following way:

1. A derived class inherits all base class methods with the following exceptions:
 Constructors, destructors and copy constructors of the base class.
 Overloaded operators of the base class.
 The friend functions of the base class.

Type of Inheritance:
2. When deriving a class from a base class, the base class may be inherited through public, protected or private
inheritance.
3. A derived class with only one base class is called single inheritance. And one with several base classes is called
multiple inheritance.
4. On the other hand the traits of one class may be inherited by more than one class. This process is known as
hierarchical inheritance.
5. The mechanism of deriving a class from another derived class is known as Multilevel inheritance.

MCOE, PUNE Page 2


Object Oriented Programming SE ECE SEM-II

#include <iostream>
using namespace std;

class A {
public:
int a = 5;
A() {
cout << "Constructor for class A" << endl;
}
};
class B {
public:
int b = 10;
B() {

cout << "Constructor for class B" << endl;


}
};
class C: public A, public B {
public:
int c = 20;
C() {

MCOE, PUNE Page 3


Object Oriented Programming SE ECE SEM-II

cout << "Constructor for class C" << endl;


cout<<"Class C inherits from class A and class B" << endl;
}
};
int main() {
C obj;
cout<<"a = "<< obj.a <<endl;
cout<<"b = "<< obj.b <<endl;
cout<<"c = "<< obj.c <<endl;
return 0;
}
The output of the above program is given as follows −

Constructor for class A


Constructor for class B
Constructor for class C
Class C inherits from class A and class B
a = 5
b = 10
c = 20

COMMENTS AND CONCLUSION:

FAQ:
What is inheritance?
What are types of inheritance?

References:
Text Books:
1. E Balagurusamy, “Object Oriented Programming Using C++ and JAVA”, Tata McGraw-Hill
2. Herbert Schildt , “ The Complete Reference TO C++” Tata McGraw-Hill,3RD Edition.
Reference books:
1. Bjarne Stroustrup, “C++ Programming Language”, Pearson Education
2. Robert Lafore, “Object-Oriented Programming in C++ “,Pearson Education India , (4th Edition)
3. Yeshwant Kanetkar “Let us C++”, BPB Publications

MCOE, PUNE Page 4


Object Oriented Programming SE ECE SEM-II

MCOE, PUNE Page 5

You might also like