Object oriented programming concepts-Session 8
Object oriented programming concepts-Session 8
nl
O
se
U
tre
en
Session: 8 C
h
ec
Overriding
pt
rA
Fo
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
se
class
U
tre
Child class use methods inherited from the parent
en
class as per its own requirement
C
h
ec
pt
O
class overridden method
se
U
tre
en
C
h
ec
pt
rA
Fo
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
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
O
method.
se
U
tre
en
C
h
ec
pt
rA
Fo
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
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
}
Fo
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
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
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