Object oriented programming concepts-Session 9
Object oriented programming concepts-Session 9
nl
O
se
U
tre
en
Session: 9 C
h
ec
Polymorphic Variable
pt
rA
Fo
O
List types of polymorphic variables
se
Explain simple polymorphic variable
U
tre
Explain pseudo-variable
en
Explain reverse polymorphism
C
h
ec
pt
rA
Fo
nl
O
reference
The figure of morevariable
shows a polymorphic than one
f1 of class
se
Father which is used to access both parent as well as
type of object
U
child class study() methods.
tre
en
C
h
ec
pt
rA
Fo
nl
variable.
O
se
Code Snippet
U
class Emp
tre
{
en
public virtual void display()
{
C
Console.WriteLine(“Class Emp”);
h
ec
}
pt
}
rA
O
// overridden method
se
public override void display()
U
{
tre
Console.WriteLine(“Class FullTimeEmp”);
}
en
}
C
// class PartTimeEmp inherits class Emp
h
class PartTimeEmp : Emp
ec
{
pt
// overridden method
rA
O
Console.WriteLine(“Class PartTimeEmp”);
se
}
U
static void Main()
tre
{
Emp e1 = new FullTimeEmp(); // polymorphic
en
variable e1
e1.display(); // line3
} C
h
ec
Output:
rA
Class FullTimeEmp
Fo
se
The pseudo-variable
U
a method and is normally not
tre
declared
‘this’ inlike
C++, a
C#,normal
and Java variable
en
C
‘self’ in Small talk
h
Eliminates the need to give different
ec
‘current’
rA
O
polymorphic assignment.
se
U
The C# code shows reverse polymorphism by assigning
tre
en
Code Snippet
C
h
ec
nl
O
Problem of identification Problem of assignment
se
The figure shows the identification and assignment
U
problem.
tre
en
C
h
ec
pt
rA
Fo
O
of more than one type of object.
se
A pseudo-variable is an invisible receiver that works
U
inside of a method and is normally not declared like a
tre
normal variable.
en
The pseudo-variable is called ‘this’ in C++, C# and Java,
C
‘self’ in Small talk, and ‘current’ in Eiffel.
h
The pseudo-variable eliminates the need to give
ec
polymorphic assignment.
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 9 11