0% found this document useful (0 votes)
3 views12 pages

Object oriented programming concepts-Session 8

The document covers key concepts in object-oriented programming, focusing on method overriding, abstract methods, and their distinctions from related concepts like overloading and shadowing. It explains how child classes can override parent class methods, the definitions of replacement and refinement, and the characteristics of abstract methods. Additionally, it provides comparisons between abstract classes and interfaces, as well as between overriding and overloading methods.

Uploaded by

olowumm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

Object oriented programming concepts-Session 8

The document covers key concepts in object-oriented programming, focusing on method overriding, abstract methods, and their distinctions from related concepts like overloading and shadowing. It explains how child classes can override parent class methods, the definitions of replacement and refinement, and the characteristics of abstract methods. Additionally, it provides comparisons between abstract classes and interfaces, as well as between overriding and overloading methods.

Uploaded by

olowumm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

y

nl
O
se
U
tre
en
Session: 8 C
h
ec

Overriding
pt
rA
Fo

Version 1.0 © 2012 Aptech Limited.


y
nl
 Explain Overriding

O
se
 Explain Abstract method and Pure virtual methods

U
Explain Replacement and Refinement

tre

en
 Differentiate between Overriding and Shadowing
C
h
 Differentiate between Overriding and Overloading
ec
pt
rA
Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 2


y
nl
O
A child class can override the method of a parent

se
class

U
tre
Child class use methods inherited from the parent

en
class as per its own requirement
C
h
ec
pt

Child class cannot change the signature (the


rA

name and parameters of the parent class method)


Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 3


y
nl
 The figure shows calling parent class method from child

O
class overridden method

se
U
tre
en
C
h
ec
pt
rA
Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 4


y
nl
Replacement - When the child class completely

O
overrides the parent class method implementation

se
U
tre
en
C
Refinement - When the child class includes the
h
functionality of the parent class version of the
ec

overridden method within its own version


pt
rA
Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 5


y
nl
An abstract method is one which is declared inside

O
parent class but not implemented there.

se
U
The characteristics of abstract methods are as follows:

tre
en
• An abstract method is considered implicitly virtual.
C
• Abstract methods are allowed only in abstract
h
classes in C# and Java.
ec

• An abstract method declaration provides no actual


pt

implementation and the method declaration simply


rA

ends with a semicolon.


Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 6


y
nl
 The figure shows an abstract class with an abstract

O
method.

se
U
tre
en
C
h
ec
pt
rA
Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 7


y
nl
 The table shows syntax of writing an abstract method.

O
C# Java C++

se
abstract public void draw(); abstract public void draw(); virtual void draw() = 0;

U
 The table lists the differences between the abstract class

tre
and interface.

en
Abstract Class Interface
Can contain methods with a body
Cannot simulate multiple C Cannot contain methods with a body
Can simulate multiple inheritance
h
ec

inheritance
Child class should be a type of Child class may not be a type of interface
pt

parent
rA

Abstract class can have private All members of interface are implicitly
members public
Fo

Enable strong naming on Specifies if assemblies have strong names


precompiled assemblies
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 8
y
nl
 The deferred methods of C# and Java are referred to as pure

O
virtual functions in C++.

se
 In C++, including a pure virtual function in a class is the only way

U
to inform the compiler that the class is abstract.

tre
en
Code Snippet
class Shape C
h
{
ec

public:
pt

virtual void Area() = 0;


rA

}
Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 9


y
nl
 Table shows the difference between overriding and overloading.

O
se
Method Overriding Method Overloading
Classes in which overridden methods Parent-child relationship is not required for

U
are used must have a parent-child overloading
relationship

tre
For overriding, the method signature For overloading, the method signature must be

en
cannot be changed changed
Overridden methods can be combined Overloaded methods are always executed
to perform the actions of both parent
C separately
h
and child class together
ec

Overriding is resolved at run-time Overloading is resolved at compile time


pt
rA
Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 10


y
nl
 Method overriding is a technique in which a child class

O
can override the method of a parent class and change

se
the implementation of the method to suit its own

U
requirement.

tre
 Replacement is a condition in which the child class

en
completely overrides the parent class method
implementation. C
h
Refinement is a condition in which the child class
ec

includes the functionality of the parent class version of


pt
rA

the overridden method within its own version.


Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 11


y
nl
 An abstract method is one which is declared inside

O
parent class but implemented in the child class.

se
 An abstract class is intended only to be a base class of

U
other classes and cannot be instantiated.

tre
 Shadowing is a technique in which a variable or

en
method declared in one scope hides a variable or
C
method with the same name in another scope.
h
ec

 Redefinition is a technique in which the name of the


pt

methods remains the same but signature of the child


rA

class method differs from that of the parent class.


Fo

Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 8 12

You might also like