SlideShare a Scribd company logo
1 of 26
Left Blank!
22/08/2015Zubair Farooq (MCS) 1
22/08/2015Hadziq Fabroyir - Informatics ITS 2
Introduction
Title: Inheritance
Class: Master Computer Science (MCS)
Subject: OOP using C++
Present by Zubair Farooq
Date 20 August, 2015
22/08/2015Hadziq Fabroyir - Informatics ITS 3
Objectives
• Inheritance
• Advantages of Inheritance
• Why we use Inheritance?
• FORMS OF INHERITANCE
• Defining a Base Class
• Defining a Derived Class
• Visibility Modes
• Inheritance Program example
22/08/2015Hadziq Fabroyir - Informatics ITS 4
Inheritance
Inheritance allows a software developer
to derive a new class from an existing one.
22/08/2015Zubair Farooq (MCS) 5
Inheritance
The existing class is called
the parent, super, or base
class.
The derived class is called a
child or subclass.
22/08/2015Zubair Farooq (MCS) 6
Inheritance
• The child inherits
characteristics of the
parent.
• The child has special
rights to the parents
methods and data.
•The child has its own
unique behaviors and
data.
22/08/2015Zubair Farooq (MCS) 7
Inheritance
Inheritance relationships are
often shown graphically in a
class diagram with the arrow
pointing to the parent class.
Inheritance should create an
is-arelationship, meaning
the child is a more specific
version of the parent.
22/08/2015Zubair Farooq (MCS) 8
Animal
Bird
Advantages of Inheritance?
Sometimes we need to repeat the code or we need
repeat the whole class properties. So It helps in various
ways.
It saves memory space.
It saves time.
It increases reliability of the code.
It saves the developing and testing efforts.
22/08/2015Zubair Farooq (MCS) 9
Why we use Inheritance?
To increase the reusability of the code and to make
further usable for another classes. We use the
concept of inheritance.
22/08/2015Zubair Farooq (MCS) 10
FORMS OF INHERITANCE
Single Inheritance:
It is the inheritance hierarchy wherein one derived class inherits from one base
class.
Multiple Inheritance:
It is the inheritance hierarchy wherein one derived class inherits from multiple
base classes.
Hierarchical Inheritance:
It is the inheritance hierarchy wherein multiple subclasses inherits from one base
class.
Multilevel Inheritance:
It is the inheritance hierarchy wherein subclass acts as a base class for other
classes.
Hybrid Inheritance:
The inheritance hierarchy that reflects any legal combination of other four types
of inheritance.
22/08/2015Zubair Farooq (MCS) 11
FORMS OF INHERITANCE
22/08/2015Zubair Farooq (MCS) 12
C# and Java support only Single inheritance, meaning that a
derived class can have only one parent class.
Defining a Base Class
Base class has general features common to all the derived
classes and derived class (apart from having all the
features of the base class) adds specific features.
class Base-class
{
... ... ...
…….//Members of base class
};
22/08/2015Zubair Farooq (MCS) 13
Defining a Derived Class
The general form of deriving a subclass from a base class is as
follows
Class derived-class-name : visibility-mode base-class-name
{
…… //
…….// members of the derived class
};
The visibility-mode is optional.
This visibility mode specifies how the features of base class are
visible to the derived class.
22/08/2015Zubair Farooq (MCS) 14
Visibility Mode
Public Inheritance
Protected Inheritance
Private Inheritance
22/08/2015Zubair Farooq (MCS) 15
Public Inheritance
class A : public B
{ // Class A now inherits the members of Class B
// with no change in the “access specifier” for
} // the inherited members
22/08/2015Zubair Farooq (MCS) 16
Protected Inheritance
class A : protected B
{ // Class A now inherits the members of Class B
// with public members “promoted” to protected
} // but no other changes to the inherited members
22/08/2015Zubair Farooq (MCS) 17
Private Inheritance
class A : private B
{ // Class A now inherits the members of Class B
// with public and protected members
} // “promoted” to private
22/08/2015Zubair Farooq (MCS) 18
Visibility Modes
22/08/2015Zubair Farooq (MCS) 19
Execution of base class
constructor
When both derived and base class contains
constructors, the base constructor is executed first
and then the constructor in the derived class is
executed.
22/08/2015Zubair Farooq (MCS) 20
Program Statement
Imagine a publishing company that markets both book and
audiocassette versions of its works.
Create a class publication that stores the title (a string) and price
(type float) of a publication. From this class derive two classes:
book, which adds a page count (type int), and tape, which adds a
playing time in minutes (type float). Each of these three classes
should have a getdata() function to get its data from the user at the
keyboard, and a putdata() function to display its data. Write a
main() program to test the book and tape classes by creating
instances of them, asking the user to fill in data with getdata(), and
then displaying the data with putdata().
Reference: Object-Oriented Programming in C++ (4th Edition) by Robert Lafore(CH-9 Ex Question #1.)
22/08/2015Zubair Farooq (MCS) 21
Base Class
classpublication{
char title[20];
float price;
public:
void getdata( ){
cout<<"Please enter thetitleand price of Book : ";
cin>>title>>price;
}
void putdata( ){
cout<<"Book Title : "<<title<<endl;
cout<<"Price: "<<price<<endl;
}
};
22/08/2015Zubair Farooq (MCS) 22
SubClass
class book : publication{
int pages;
public:
void getdata(){
publication::getdata();
cout<<"ENter the number of pages : ";
cin>>pages;
}
Void putdata () {
publication::putdata();
cout<<"Pages : "<<pages<<endl;
}
};
22/08/2015Zubair Farooq (MCS) 23
SubClass
class tape : publication{
float time;
public:
void getdata(){
publication::getdata();
cout<<"Enter time play in minute : ";
cin>>time;
}
void putdata(){
publication::putdata();
cout<<"Playing time : "<<time;
}
};
22/08/2015Zubair Farooq (MCS) 24
Mian() Function
int main(void)
{
clrscr();
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
getch();
return 0;
}
22/08/2015Zubair Farooq (MCS) 25
Feel Free to ask any
Questions.
22/08/2015Zubair Farooq (MCS) 26

More Related Content

What's hot

#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 

What's hot (20)

inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Inheritance in c++ part1
Inheritance in c++ part1Inheritance in c++ part1
Inheritance in c++ part1
 
Inheritance in c++theory
Inheritance in c++theoryInheritance in c++theory
Inheritance in c++theory
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to Inheritance
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 

Viewers also liked

C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
shatha00
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
Hadziq Fabroyir
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 

Viewers also liked (13)

Inheritance
InheritanceInheritance
Inheritance
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : Inheritance
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
constructor and destructor-object oriented programming
constructor and destructor-object oriented programmingconstructor and destructor-object oriented programming
constructor and destructor-object oriented programming
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 

Similar to Oop inheritance

Similar to Oop inheritance (20)

ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
 
OOP
OOPOOP
OOP
 
Lecturespecial
LecturespecialLecturespecial
Lecturespecial
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Inheritance
Inheritance Inheritance
Inheritance
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
lecture3.pptx
lecture3.pptxlecture3.pptx
lecture3.pptx
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
 
Oose unit 3 ppt
Oose unit 3 pptOose unit 3 ppt
Oose unit 3 ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
OOSE Unit 3 PPT.ppt
OOSE Unit 3 PPT.pptOOSE Unit 3 PPT.ppt
OOSE Unit 3 PPT.ppt
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
Inheritance
InheritanceInheritance
Inheritance
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 

Recently uploaded (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 

Oop inheritance

  • 2. 22/08/2015Hadziq Fabroyir - Informatics ITS 2
  • 3. Introduction Title: Inheritance Class: Master Computer Science (MCS) Subject: OOP using C++ Present by Zubair Farooq Date 20 August, 2015 22/08/2015Hadziq Fabroyir - Informatics ITS 3
  • 4. Objectives • Inheritance • Advantages of Inheritance • Why we use Inheritance? • FORMS OF INHERITANCE • Defining a Base Class • Defining a Derived Class • Visibility Modes • Inheritance Program example 22/08/2015Hadziq Fabroyir - Informatics ITS 4
  • 5. Inheritance Inheritance allows a software developer to derive a new class from an existing one. 22/08/2015Zubair Farooq (MCS) 5
  • 6. Inheritance The existing class is called the parent, super, or base class. The derived class is called a child or subclass. 22/08/2015Zubair Farooq (MCS) 6
  • 7. Inheritance • The child inherits characteristics of the parent. • The child has special rights to the parents methods and data. •The child has its own unique behaviors and data. 22/08/2015Zubair Farooq (MCS) 7
  • 8. Inheritance Inheritance relationships are often shown graphically in a class diagram with the arrow pointing to the parent class. Inheritance should create an is-arelationship, meaning the child is a more specific version of the parent. 22/08/2015Zubair Farooq (MCS) 8 Animal Bird
  • 9. Advantages of Inheritance? Sometimes we need to repeat the code or we need repeat the whole class properties. So It helps in various ways. It saves memory space. It saves time. It increases reliability of the code. It saves the developing and testing efforts. 22/08/2015Zubair Farooq (MCS) 9
  • 10. Why we use Inheritance? To increase the reusability of the code and to make further usable for another classes. We use the concept of inheritance. 22/08/2015Zubair Farooq (MCS) 10
  • 11. FORMS OF INHERITANCE Single Inheritance: It is the inheritance hierarchy wherein one derived class inherits from one base class. Multiple Inheritance: It is the inheritance hierarchy wherein one derived class inherits from multiple base classes. Hierarchical Inheritance: It is the inheritance hierarchy wherein multiple subclasses inherits from one base class. Multilevel Inheritance: It is the inheritance hierarchy wherein subclass acts as a base class for other classes. Hybrid Inheritance: The inheritance hierarchy that reflects any legal combination of other four types of inheritance. 22/08/2015Zubair Farooq (MCS) 11
  • 12. FORMS OF INHERITANCE 22/08/2015Zubair Farooq (MCS) 12 C# and Java support only Single inheritance, meaning that a derived class can have only one parent class.
  • 13. Defining a Base Class Base class has general features common to all the derived classes and derived class (apart from having all the features of the base class) adds specific features. class Base-class { ... ... ... …….//Members of base class }; 22/08/2015Zubair Farooq (MCS) 13
  • 14. Defining a Derived Class The general form of deriving a subclass from a base class is as follows Class derived-class-name : visibility-mode base-class-name { …… // …….// members of the derived class }; The visibility-mode is optional. This visibility mode specifies how the features of base class are visible to the derived class. 22/08/2015Zubair Farooq (MCS) 14
  • 15. Visibility Mode Public Inheritance Protected Inheritance Private Inheritance 22/08/2015Zubair Farooq (MCS) 15
  • 16. Public Inheritance class A : public B { // Class A now inherits the members of Class B // with no change in the “access specifier” for } // the inherited members 22/08/2015Zubair Farooq (MCS) 16
  • 17. Protected Inheritance class A : protected B { // Class A now inherits the members of Class B // with public members “promoted” to protected } // but no other changes to the inherited members 22/08/2015Zubair Farooq (MCS) 17
  • 18. Private Inheritance class A : private B { // Class A now inherits the members of Class B // with public and protected members } // “promoted” to private 22/08/2015Zubair Farooq (MCS) 18
  • 20. Execution of base class constructor When both derived and base class contains constructors, the base constructor is executed first and then the constructor in the derived class is executed. 22/08/2015Zubair Farooq (MCS) 20
  • 21. Program Statement Imagine a publishing company that markets both book and audiocassette versions of its works. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Each of these three classes should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display its data. Write a main() program to test the book and tape classes by creating instances of them, asking the user to fill in data with getdata(), and then displaying the data with putdata(). Reference: Object-Oriented Programming in C++ (4th Edition) by Robert Lafore(CH-9 Ex Question #1.) 22/08/2015Zubair Farooq (MCS) 21
  • 22. Base Class classpublication{ char title[20]; float price; public: void getdata( ){ cout<<"Please enter thetitleand price of Book : "; cin>>title>>price; } void putdata( ){ cout<<"Book Title : "<<title<<endl; cout<<"Price: "<<price<<endl; } }; 22/08/2015Zubair Farooq (MCS) 22
  • 23. SubClass class book : publication{ int pages; public: void getdata(){ publication::getdata(); cout<<"ENter the number of pages : "; cin>>pages; } Void putdata () { publication::putdata(); cout<<"Pages : "<<pages<<endl; } }; 22/08/2015Zubair Farooq (MCS) 23
  • 24. SubClass class tape : publication{ float time; public: void getdata(){ publication::getdata(); cout<<"Enter time play in minute : "; cin>>time; } void putdata(){ publication::putdata(); cout<<"Playing time : "<<time; } }; 22/08/2015Zubair Farooq (MCS) 24
  • 25. Mian() Function int main(void) { clrscr(); book b; tape t; b.getdata(); t.getdata(); b.putdata(); t.putdata(); getch(); return 0; } 22/08/2015Zubair Farooq (MCS) 25
  • 26. Feel Free to ask any Questions. 22/08/2015Zubair Farooq (MCS) 26

Editor's Notes

  1. The child inherits characteristics of the parent. Methods and data defined for the parent class. The child has special rights to the parents methods and data. Public access like any one else Protected access available only to child classes (and their descendants). The child has its own unique behaviors and data.