SlideShare a Scribd company logo
1 of 24
Object Oriented
Programming using C++
Inheritance
INHERITANCE
Inheritance
Inheritance is a phenomenon of acquiring
properties from predecessor.
In object oriented systems, it means
acquiring the properties of base class to the
derived class.
Hence the derived class gets specialized with
the properties of base class as well as its own
properties.
It involves the concept of code reusability.
Inheritance
Inheritance is the process by which new classes
called derived classes are created from existing
classes called base classes.
The derived classes have all the features of the
base class and the programmer can choose to
add new features specific to the newly created
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.
Types of inheritance:
single level
multi level
Base Class A
Derived Class B
Class A
Intermediate
derived class B
Derived Class C
Types of inheritance:
Multiple inheritance
Hierarchical inheritance.
Base class A Base class B
Derived Class
C
Class A
Derived class B
Derived
class C
Derived class
D
Types of inheritance:
Hybrid inheritance
Class A
Intermediate
Derived class B
Intermediate
Derived class C
Derived class D
Class A
Class B
Class C
Class D
FEATURES /ADVANTAGES OF
INHERITANCE
Reusability of Code
Saves Time and Effort
Faster development, easier maintenance and
easy to extend
Capable of expressing the inheritance
relationship and its transitive nature which
ensures closeness with real world problems
Syntax for inheritance:
class Base-class-name
{
___ //
___ // definition of the class
};
class derived-class name : visibility-mode
base-class-name
{
….. //
….. // members of derived class
};
Visibility Mode
Here visibility mode can be public, private
or protected.
Private is the default mode. They are visible
to member functions within its class.
Protected visible to member functions of
its own class and derived class.
Public visible to all functions in the
program.
When a class is inherited in any
of these visibility modes, the
visibility of its members varies.
The visibility of inherited members is
as shown:
Single level
In this kind of inheritance, there is a single
base class and a single derived class.
Eg: class base
{
// class declaration
};
class derived : public base
{
//derive class declaration
};
Here, base class base is inherited into the derived class derived.
Multi level Inheritance
In this type of inheritance
there is more than one
levels of inheritance and
each derived class serves as
the base class for the other
derived class.
Eg. class base1
{
//base1 declaration
};
class base2: public base1
{
//base2 declaration
};
class derived : public base2
{
//derived class
declaration
};
Here, base1 is a base class that
is inherited into the derived
class base2, which in turn is
inherited into the derived
class derived.
Question to implement
A class A{
char name[] …….
int roll_no; ……
+void get();
+void show(); };
B class B: public A
float m1,m2,m3; {
+void take(); …..
+void put(); };
C
class C: public B
float percentage; {
+void cal_per(); …..
+void disp_result(); };
Multiple Inheritance –
In this kind of Inheritance, there are many base classes and
one derived class from these base classes.
Eg. Class base1{};
class base2{};
Class base 3{};
class derived : public base1, protected base2, public base3
{
// class declaration
};
Here, base1, base2 and base3 are base classes that are
inherited into the derived class derived.
Hierarchical Inheritance
In this type of Inheritance, there
is one base class and many
derived classes from this base
class
Eg. class base
{
// class declaration
};
class der1 : public base
{
// class declaration
};
class der2 : public base
{
// class declaration
};
Here, der1 and der2 are derived
classes that are derived from
the base class base.
Hybrid Inheritance
This is a combination of one or more
than one type of Inheritance, like a
combination of multiple and multilevel
inheritance.
Virtual Base Classes
In hybrid Inheritance, that is a combination of
multiple and hierarchical inheritance, there may
arise a case when the features of ancestor base
class are inherited via multiple paths in to the
ultimate derived class, resulting in deriving
duplicate set of members.
This duplication of inherited members can be
avoided in C++ by inheriting the ancestor base
class as virtual base class in to any derived class.
Hybrid inheritance
Class A
Intermediate
Derived class B1
Intermediate
Derived class B2
Derived class C
Class A
{
// (ancestor) class declaration
};
Class B1: virtual public A
{
//(intermediate derived) class
declaration
};
Class B2: virtual public A
{
//(intermediate derived) class
declaration
};
Class C: public B1, public B2
{// only one copy of the
members of class A is inherited
};
Syntax:
Class A
{
// (ancestor) class declaration
};
Class B1: virtual public A
{
//(intermediate derived) class declaration
};
Class B2: virtual public A
{
//(intermediate derived) class declaration
};
Class C: public B1, public B2
{// only one copy of the members of class A is inherited
};
Constructors in derived class:
• Whenever we have parameterized
constructors in Base class, it becomes
necessary to define a parameterized
constructor in derived class so that on the
creation of objects of derived class, we can
pass the parameters to the base constructors
through the derived constructor.
The format for the derived class constructor in this case
is a bit different as shown below:
class derived: <visibility mode> <base class name>
{
int A, B; //declaration of data members of class Derived
Public:
derived( arg 1, arg 2, arg 3…. arg N): base 1( arg a,arg b,,…,arg
d), base 2( arg e, arg f,… arg k),…base N( arg l, arg m…,arg p)
{
A= arg 1;
B= arg 2;
}
};
Abstract Classes
• Is one that is used to create objects.
• An abstract class is designed only to act as a
base class(to be inherited by other classes).

More Related Content

What's hot

Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7kamal kotecha
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++RAJ KUMAR
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++Nikunj Patel
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oopsHirra Sultan
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 

What's hot (20)

inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
OOP C++
OOP C++OOP C++
OOP C++
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Inheritance
InheritanceInheritance
Inheritance
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++EASY TO LEARN INHERITANCE IN C++
EASY TO LEARN INHERITANCE IN C++
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 

Similar to Inheritance

Similar to Inheritance (20)

Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance (with classifications)
Inheritance (with classifications)Inheritance (with classifications)
Inheritance (with classifications)
 
Inheritance
InheritanceInheritance
Inheritance
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
iheritence.pptx
iheritence.pptxiheritence.pptx
iheritence.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdf
 
inheritance
   inheritance   inheritance
inheritance
 
inheritence
inheritenceinheritence
inheritence
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Ritik (inheritance.cpp)
Ritik (inheritance.cpp)Ritik (inheritance.cpp)
Ritik (inheritance.cpp)
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 

Recently uploaded

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 

Inheritance

  • 3. Inheritance Inheritance is a phenomenon of acquiring properties from predecessor. In object oriented systems, it means acquiring the properties of base class to the derived class. Hence the derived class gets specialized with the properties of base class as well as its own properties. It involves the concept of code reusability.
  • 4. Inheritance Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created 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.
  • 5. Types of inheritance: single level multi level Base Class A Derived Class B Class A Intermediate derived class B Derived Class C
  • 6. Types of inheritance: Multiple inheritance Hierarchical inheritance. Base class A Base class B Derived Class C Class A Derived class B Derived class C Derived class D
  • 7. Types of inheritance: Hybrid inheritance Class A Intermediate Derived class B Intermediate Derived class C Derived class D Class A Class B Class C Class D
  • 8. FEATURES /ADVANTAGES OF INHERITANCE Reusability of Code Saves Time and Effort Faster development, easier maintenance and easy to extend Capable of expressing the inheritance relationship and its transitive nature which ensures closeness with real world problems
  • 9. Syntax for inheritance: class Base-class-name { ___ // ___ // definition of the class }; class derived-class name : visibility-mode base-class-name { ….. // ….. // members of derived class };
  • 10. Visibility Mode Here visibility mode can be public, private or protected. Private is the default mode. They are visible to member functions within its class. Protected visible to member functions of its own class and derived class. Public visible to all functions in the program.
  • 11. When a class is inherited in any of these visibility modes, the visibility of its members varies.
  • 12. The visibility of inherited members is as shown:
  • 13. Single level In this kind of inheritance, there is a single base class and a single derived class. Eg: class base { // class declaration }; class derived : public base { //derive class declaration }; Here, base class base is inherited into the derived class derived.
  • 14. Multi level Inheritance In this type of inheritance there is more than one levels of inheritance and each derived class serves as the base class for the other derived class. Eg. class base1 { //base1 declaration }; class base2: public base1 { //base2 declaration }; class derived : public base2 { //derived class declaration }; Here, base1 is a base class that is inherited into the derived class base2, which in turn is inherited into the derived class derived.
  • 15. Question to implement A class A{ char name[] ……. int roll_no; …… +void get(); +void show(); }; B class B: public A float m1,m2,m3; { +void take(); ….. +void put(); }; C class C: public B float percentage; { +void cal_per(); ….. +void disp_result(); };
  • 16. Multiple Inheritance – In this kind of Inheritance, there are many base classes and one derived class from these base classes. Eg. Class base1{}; class base2{}; Class base 3{}; class derived : public base1, protected base2, public base3 { // class declaration }; Here, base1, base2 and base3 are base classes that are inherited into the derived class derived.
  • 17. Hierarchical Inheritance In this type of Inheritance, there is one base class and many derived classes from this base class Eg. class base { // class declaration }; class der1 : public base { // class declaration }; class der2 : public base { // class declaration }; Here, der1 and der2 are derived classes that are derived from the base class base.
  • 18. Hybrid Inheritance This is a combination of one or more than one type of Inheritance, like a combination of multiple and multilevel inheritance.
  • 19. Virtual Base Classes In hybrid Inheritance, that is a combination of multiple and hierarchical inheritance, there may arise a case when the features of ancestor base class are inherited via multiple paths in to the ultimate derived class, resulting in deriving duplicate set of members. This duplication of inherited members can be avoided in C++ by inheriting the ancestor base class as virtual base class in to any derived class.
  • 20. Hybrid inheritance Class A Intermediate Derived class B1 Intermediate Derived class B2 Derived class C Class A { // (ancestor) class declaration }; Class B1: virtual public A { //(intermediate derived) class declaration }; Class B2: virtual public A { //(intermediate derived) class declaration }; Class C: public B1, public B2 {// only one copy of the members of class A is inherited };
  • 21. Syntax: Class A { // (ancestor) class declaration }; Class B1: virtual public A { //(intermediate derived) class declaration }; Class B2: virtual public A { //(intermediate derived) class declaration }; Class C: public B1, public B2 {// only one copy of the members of class A is inherited };
  • 22. Constructors in derived class: • Whenever we have parameterized constructors in Base class, it becomes necessary to define a parameterized constructor in derived class so that on the creation of objects of derived class, we can pass the parameters to the base constructors through the derived constructor.
  • 23. The format for the derived class constructor in this case is a bit different as shown below: class derived: <visibility mode> <base class name> { int A, B; //declaration of data members of class Derived Public: derived( arg 1, arg 2, arg 3…. arg N): base 1( arg a,arg b,,…,arg d), base 2( arg e, arg f,… arg k),…base N( arg l, arg m…,arg p) { A= arg 1; B= arg 2; } };
  • 24. Abstract Classes • Is one that is used to create objects. • An abstract class is designed only to act as a base class(to be inherited by other classes).