Академический Документы
Профессиональный Документы
Культура Документы
ASSIGNMENT
MISS
FIZZAH SOHAIL
QUESTION # 01:
Figure out the type of polymorphism is method
overloading and method overriding respectively.
1. Method overriding
2. Method overloading
Method overloading means writing two or more methods in the same
class by using same method name, but the passing parameters is
different.
Method overriding means we use the method names in the different
classes,that means parent class method is used in the child class.
In Java to achieve polymorphism a super class reference variable can
hold the sub class object.
}
}
OUTPUT
sum of no is 25
sum of no is 20
}
}
Output
sum of no is 15
sum of no is 7.0
// Driver class
class Main
{
public static void main(String[] args)
{
// If a Parent type reference refers
// to a Parent object, then Parent's
// show is called
Parent obj1 = new Parent();
obj1.show();
QUESTION # 02:
Is constructor overloading polymorphism? If Yes or No, Justify
yourAnswer.
ANSWER:
In runtime polymorphism, which function should be called is decided at
runtime. In constructor overloading, its parameter will be used at compile
time to decide which instance should be called Constructor overloading
is compile time, but overriding is runtime polymorphism.