Object-Oriented Programming: Overriding and Overloading Member Functions of Base Classes, Slides of Object Oriented Programming

An explanation of overriding and overloading member functions of base classes in object-oriented programming (oop). Overloading is done within the scope of one class, while overriding is done in the scope of both parent and child classes. The document also includes examples of overriding member functions and their impact on the output.

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 14

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. 25
Lecture No. 25
Overriding Member Functions of
Overriding Member Functions of
Base Class
Base Class
Derived class can override the member
Derived class can override the member
functions of its base class
functions of its base class
To override a function the derived class
To override a function the derived class
simply provides a function with the same
simply provides a function with the same
signature as that of its base class
signature as that of its base class
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Object-Oriented Programming: Overriding and Overloading Member Functions of Base Classes and more Slides Object Oriented Programming in PDF only on Docsity!

Object

Object

Oriented Programming

Oriented Programming

(OOP)

(OOP)

Lecture No. 25

Lecture No. 25

Overriding

Overriding

Parent

Func

Child

Func

docsity.com

Overriding Member Functions of

Overriding Member Functions of

Base Class

Base Class

Derive class can override member function

Derive class can override member function

of base class such that the working of

of base class such that the working of

function is totally changed function is totally changed

Overriding Member Functions of

Overriding Member Functions of

Base Class

Base Class

Derive class can override member function

Derive class can override member function

of base class such that the working of

of base class such that the working of

function

function is similar

is similar to former implementation

to former implementation

OutputOutput

Output:

Output:

Name: Ahmed

Name: Ahmed

Major: Computer Science

Major: Computer Science

Example

Example

class Student : public Person{

class Student : public Person{

char * major;

char * major;

public:

public:

Student(char * aName, char* m);

Student(char * aName, char* m);

void Print(){

void Print(){

Print();//Print of Person

Print();//Print of Person

cout<<

cout<< “

Major:

Major: ”

<< major <<endl;

<< major <<endl;

ExampleExample

int main(){

int main(){

Student a(

Student a(

Ahmad

Ahmad

Computer

Computer

Science

Science

a.Print(); a.Print();

return 0;

return 0;

Overriding Member Functions of

Overriding Member Functions of

Base Class

Base Class

The pointer must be used with care when

The pointer must be used with care when

working with overridden member

working with overridden member

functions

functions

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

Direct Base Class

Direct Base Class

A direct base class is explicitly listed in a derived

A direct base class is explicitly listed in a derived

class's class's header with a colon (:)header with a colon (:)

class Child1:public Parent1class Child1:public Parent