Академический Документы
Профессиональный Документы
Культура Документы
RIT2009013
LOKESH KUMAR
Output :
OUTPUT-of program is :
Explaination:
I am in methodInterfaceOne of class classTwo
Explanation:
Explanation:
((InterfaceTwo) i1).methodInterfaceTwo();
Explanation
Explanation:
Explanation:
Explanation:
Explanation:
Explanation:
String var5 = i2.toString();
var6 : javaapplication2.C1@190d11
Explanation:
InterfaceOne i3 = new C1();
String var6 = i3.toString();
System.out.println("var6 : " + var6);
I3 is used to instantiate the object of class c1 This is possible since classc1 extends
interfaceTwo which extends interfaceOne and i3 can hold a reference of type
interfaceOne .
toString method from object class is called which converts integer to string
It is printed .
Explanation:
Object is parent class of all the classes and its object is used to instantiate
classTwo object
Explanation:
It is type casted to hold a reference of interfaceTwo but it can still refer
classTwo object
And methodInterfaceOne(); of classTwo object is called which prints ” I am
in methodInterfaceOne of class classTwo
Explanation:
Q 2) Answer-
A child object can be referenced using a parent class reference. This is the most
fundamental use of polymorphism because using a parent class reference to
refer to a child object is what allows you to take advantage of the benefits of
polymorphism.
The left side of the equation creates a reference p of type Employee. The
right side of the equation is a new Salary object.
The is a relationship carries over to polymorphism. The right side of the equation
is a Salary object. A Salary object is an Employee object.
Polymorphic parameters:
A common use of polymorphism is to create a collection of data that is not all the
same type, but has a common parent. A collection of different objects is referred to
as a heterogeneous collection.
The left side of the equation creates a reference p of type Employee. The
right side of the equation is a new Salary object.