SlideShare ist ein Scribd-Unternehmen logo
1 von 37
  INHERITANCE
[object Object],[object Object],[object Object]
Types of Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object]
SINGLE INHERITANCE ,[object Object],[object Object],[object Object],A B
When a derived class inherit from multiple base classes it is known as multiple Inheritance. A B C MULTIPLE INHERITANCE Base Class Derived Class
MULTILEVEL INHERITANCE ,[object Object],[object Object],[object Object],[object Object],[object Object],A B C
HYBRID   INHERITANCE ,[object Object],w x y z
HIERARCHICAL INHERITANCE ,[object Object],[object Object],[object Object],a b c d
A general form to defining a derived class is: Class derived class name: visibility mode  base class  name {  members of derived class }  ; Class ABC: public XYZ {  members of ABC };  DEFINING DERIVED CLASS
Example of derived class definition is: Class Sub : public Super   public derivation {  ………  members of sub }; Class Sub: private Super   private derivation { …… ...  members of sub }; Class Sub: protected Super   protected derivation { …… ...  members of sub };
MULTIPLE INHERITANCE Example of derived class definition is: Class derived_class : vis_mode base1, vis_mode base 2 { ………… .  members of derived class }; Class Sub : public SuperA, private SuperB {  ………  members of sub };
Visibility Modes ,[object Object],[object Object],[object Object]
Private Visibility Mode-   The public and protected members of the base class become private members of the derived class. The inherited members can only be accessed only through the member function of derived class. Protected Visibility Mode-   The public and protected members of base class become protected members of the derived class.
Visibility of Inherited base class members in Derived Class. Visibility Mode Public members of base class becomes Protected members of base class becomes Private members of the base class is not accessible to the derived class. Public Public Protected Protected Protected Protected Private Private Private
Accessibility of Base class members  No No Yes Private No Yes Yes Protected Yes Yes Yes Public Accessible from objects outside class Accessible from derived class Accessible from own class Access Specifier
Inheritance and Constructors and Destructors  ,[object Object],[object Object]
Class super  { …… . }; Class Sub : public Super  { ….. }; int main() {  sub ob1; …… . }
Base class Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class Base { int a;  float b; public : Base(int I, float j) { a = i;  b = j; } … }; Class Derived : public Base {…. Public :  Derived ( int p, float q) : Base (p , q)  {  } }; Even if derived const does not need a parameter, yet it accepts parameter for base const.
Class Base { int a;  float b; public : Base( int i, float j) { a = i;  b = j; } … }; Class Derived : public Base { int x; float y; Public :  Derived ( int i, int j , int p, float q) : Base (p , q)  {  x = i ; Y = j ;  } }; Derived Const is accepting parameter for itself( i ,j) and ( p , q) for Base const
Constructor in Derived Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class gamma: public beta, public alpha { int k; public: gamma(int a,float b, int c): alpha(a) , beta(b) { k=c; } void show() { cout<<“1”<<x<<“2”<<y<<“3”<<k; }}; void main() { gamma g(14,15.2,17); g.show(); }
Facts about inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract class A class that serves only as a base class from which other classes can be derived, but no objects of this base type exist, is known as abstract class.
Constructors in Multiple inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class base2  {  Protected : int b; public : Base2(int y) {  b = y;  cout<<“Constructing Base2”;  } ~Base2 ( ) {  cout<< Destructing Base2 “;  } }; Class derived : public Base2, public Base1 {  int c; public :  derived (int I, int j, int k): Base2(i), Base1(j) { c = k;  cout <<“Constructing Derived”;  }
~ Derived ( ) {  cout << Destructing Derived “;  } Void show( ) {  cout <<“1.”<<a<<“ 2.”<<b <<“ 3.”<<c;  } }; Int main ( ) {  Clrscr(); Derived ob(14,15,16); Ob.show(); } ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Virtual Base class Example  Class Base  {  public : int a ; }; Class D1 : public Base   D1 inherits Base {  public : int b ; }; Class D2 : public Base   D2 inherits Base {  public : int c ; }; Class D3 : public D1, public D2  D3 inherits D1 and D2 {  public :  int total; }; Void main ( ) { D3 ob; ob.a = 25  this is ambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Remedy
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Void main ( ) { D3 ob; ob.a = 25   now unambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
Example of Multilevel Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
class test: public student {   protected:   float sub1;   float sub2;   public:   void getmarks()   {   cout<<&quot;enter the marks of sub1,sub2&quot;;   cin>>sub1>>sub2;   }   void putmarks()   {   cout<<&quot;marks in sub1=&quot;<<sub1;   cout<<&quot;marks in sub2=&quot;<<sub2;   } };
class result : public test {   float total;   public:   void display(void)   {    total=sub1+sub2;   putnumber();   putmarks();   cout<<&quot;Total&quot;<<total;   }   };   void main()   {   result a;   a.get_number();   a.getmarks();   a.display();   }
  ANY QUERY   THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt?

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 

Was ist angesagt? (20)

Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
 
Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
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++
 
Inheritance
InheritanceInheritance
Inheritance
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Friend Function
Friend FunctionFriend Function
Friend Function
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Interface
InterfaceInterface
Interface
 
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...
 

Andere mochten auch

Inheritance
InheritanceInheritance
Inheritance
Tech_MX
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchy
myrajendra
 
Pedigree analysis
Pedigree analysisPedigree analysis
Pedigree analysis
Amy Allen
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 

Andere mochten auch (20)

Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
Inheritance
InheritanceInheritance
Inheritance
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchy
 
Genetics pedigree problems
Genetics pedigree problemsGenetics pedigree problems
Genetics pedigree problems
 
Basis of Genetic Inheritance
Basis of Genetic InheritanceBasis of Genetic Inheritance
Basis of Genetic Inheritance
 
Pedigree Basics!
Pedigree Basics!Pedigree Basics!
Pedigree Basics!
 
Pedigree analysis
Pedigree analysisPedigree analysis
Pedigree analysis
 
THE LAWS OF MENDEL
THE LAWS OF MENDELTHE LAWS OF MENDEL
THE LAWS OF MENDEL
 
Inheritance
InheritanceInheritance
Inheritance
 
pedigree analysis
 pedigree analysis pedigree analysis
pedigree analysis
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 

Ähnlich wie Inheritance

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
deepakskb2013
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
FALLEE31188
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
bunnykhan
 

Ähnlich wie Inheritance (20)

inhertance c++
inhertance c++inhertance c++
inhertance c++
 
lecture-2021inheritance-160705095417.pdf
lecture-2021inheritance-160705095417.pdflecture-2021inheritance-160705095417.pdf
lecture-2021inheritance-160705095417.pdf
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Lab3
Lab3Lab3
Lab3
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
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
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance and Interfaces
Inheritance and InterfacesInheritance and Interfaces
Inheritance and Interfaces
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
 

Mehr von poonam.rwalia (7)

1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Computer Ethics
Computer EthicsComputer Ethics
Computer Ethics
 
IT
ITIT
IT
 
Benefits Of Computer Software
Benefits Of Computer SoftwareBenefits Of Computer Software
Benefits Of Computer Software
 
Internet
InternetInternet
Internet
 
GIS
GISGIS
GIS
 

Kürzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

Inheritance

  • 2.
  • 3.
  • 4.
  • 5. When a derived class inherit from multiple base classes it is known as multiple Inheritance. A B C MULTIPLE INHERITANCE Base Class Derived Class
  • 6.
  • 7.
  • 8.
  • 9. A general form to defining a derived class is: Class derived class name: visibility mode base class name { members of derived class } ; Class ABC: public XYZ { members of ABC }; DEFINING DERIVED CLASS
  • 10. Example of derived class definition is: Class Sub : public Super public derivation { ……… members of sub }; Class Sub: private Super private derivation { …… ... members of sub }; Class Sub: protected Super protected derivation { …… ... members of sub };
  • 11. MULTIPLE INHERITANCE Example of derived class definition is: Class derived_class : vis_mode base1, vis_mode base 2 { ………… . members of derived class }; Class Sub : public SuperA, private SuperB { ……… members of sub };
  • 12.
  • 13. Private Visibility Mode- The public and protected members of the base class become private members of the derived class. The inherited members can only be accessed only through the member function of derived class. Protected Visibility Mode- The public and protected members of base class become protected members of the derived class.
  • 14. Visibility of Inherited base class members in Derived Class. Visibility Mode Public members of base class becomes Protected members of base class becomes Private members of the base class is not accessible to the derived class. Public Public Protected Protected Protected Protected Private Private Private
  • 15. Accessibility of Base class members No No Yes Private No Yes Yes Protected Yes Yes Yes Public Accessible from objects outside class Accessible from derived class Accessible from own class Access Specifier
  • 16.
  • 17. Class super { …… . }; Class Sub : public Super { ….. }; int main() { sub ob1; …… . }
  • 18.
  • 19. Class Base { int a; float b; public : Base(int I, float j) { a = i; b = j; } … }; Class Derived : public Base {…. Public : Derived ( int p, float q) : Base (p , q) { } }; Even if derived const does not need a parameter, yet it accepts parameter for base const.
  • 20. Class Base { int a; float b; public : Base( int i, float j) { a = i; b = j; } … }; Class Derived : public Base { int x; float y; Public : Derived ( int i, int j , int p, float q) : Base (p , q) { x = i ; Y = j ; } }; Derived Const is accepting parameter for itself( i ,j) and ( p , q) for Base const
  • 21.
  • 22. Class gamma: public beta, public alpha { int k; public: gamma(int a,float b, int c): alpha(a) , beta(b) { k=c; } void show() { cout<<“1”<<x<<“2”<<y<<“3”<<k; }}; void main() { gamma g(14,15.2,17); g.show(); }
  • 23.
  • 24.
  • 25.
  • 26. Abstract class A class that serves only as a base class from which other classes can be derived, but no objects of this base type exist, is known as abstract class.
  • 27.
  • 28. Class base2 { Protected : int b; public : Base2(int y) { b = y; cout<<“Constructing Base2”; } ~Base2 ( ) { cout<< Destructing Base2 “; } }; Class derived : public Base2, public Base1 { int c; public : derived (int I, int j, int k): Base2(i), Base1(j) { c = k; cout <<“Constructing Derived”; }
  • 29.
  • 30. Virtual Base class Example Class Base { public : int a ; }; Class D1 : public Base D1 inherits Base { public : int b ; }; Class D2 : public Base D2 inherits Base { public : int c ; }; Class D3 : public D1, public D2 D3 inherits D1 and D2 { public : int total; }; Void main ( ) { D3 ob; ob.a = 25 this is ambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
  • 31.
  • 32.
  • 33. Void main ( ) { D3 ob; ob.a = 25 now unambiguous Ob.b = 50; Ob.c = 75; Ob.total = ob.a +ob.b + ob.c; Cout <<ob.a<<“”<< ob.b<<“”<< ob.c<<“”<< ob.total<<“”<<“”; }
  • 34.
  • 35. class test: public student { protected: float sub1; float sub2; public: void getmarks() { cout<<&quot;enter the marks of sub1,sub2&quot;; cin>>sub1>>sub2; } void putmarks() { cout<<&quot;marks in sub1=&quot;<<sub1; cout<<&quot;marks in sub2=&quot;<<sub2; } };
  • 36. class result : public test { float total; public: void display(void) { total=sub1+sub2; putnumber(); putmarks(); cout<<&quot;Total&quot;<<total; } }; void main() { result a; a.get_number(); a.getmarks(); a.display(); }
  • 37. ANY QUERY THANK YOU