Indirect Base Class-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Indirect, Base, Class, Hierarchy, Levels, Header, Error, Protected, Public, Derived, Hidden, Access

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object
Object-
-Oriented Programming
Oriented Programming
(OOP)
(OOP)
Lecture No. 26
Lecture No. 26
Hierarchy of Inheritance
Hierarchy of Inheritance
We represent the classes involved in
We represent the classes involved in
inheritance relation in tree like hierarchy
inheritance relation in tree like hierarchy
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Indirect Base Class-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

ObjectObject--Oriented ProgrammingOriented Programming

(OOP)(OOP)

Lecture No. 26 Lecture No. 26

ExampleExample

GrandParent

Parent1 Parent

Child1 Child

ExampleExample

class GrandParent{ class GrandParent{

int gpData; int gpData;

public: public:

GrandParent() : gpData(0){...} GrandParent() : gpData(0){...}

GrandParent(int i) : gpData(i){...} GrandParent(int i) : gpData(i){...}

void Print() const; void Print() const;

ExampleExample

class Child1 : public Parent1 { class Child1 : public Parent1 {

public: public:

Child1() : Parent1() Child1() : Parent1() {...}{...}

Child1(int i) : GrandParent (i) Child1(int i) : GrandParent (i) //Error//Error

void Print() const; void Print() const;

ExampleExample

int main(){ int main(){

Child1 obj; Child1 obj;

obj.Print(); obj.Print();

obj.Parent1::Print(); obj.Parent1::Print();

obj.GrandParent::Print(); obj.GrandParent::Print();

return 0; return 0;

Types of InheritanceTypes of Inheritance

►►^ There are three types of inheritanceThere are three types of inheritance

 PublicPublic  ProtectedProtected ^ PrivatePrivate

►► Use keyword public, private or protectedUse keyword public, private or protected

to specify the type of inheritance to specify the type of inheritance

Private InheritancePrivate Inheritance

► ► If the user does not specifies the type ofIf the user does not specifies the type of

inheritance then the default type is private inheritance then the default type is private

inheritance inheritance

class Child: class Child: privateprivate Parent {Parent {……}}

is equivalent to is equivalent to

class Child: Parent { class Child: Parent {……}}

ExampleExample

class Collection { class Collection { ... ... public: public: void AddElement(int); void AddElement(int); bool SearchElement(int); bool SearchElement(int); bool SearchElementAgain(int); bool SearchElementAgain(int); bool DeleteElement(int); bool DeleteElement(int); }; };