Professional Documents
Culture Documents
ASSIGNMNT
ASSIGNMNT
ASSIGNMENT
Figure out the type of polymorphism is method overloading and method overriding
respectively.
Is constructor overloading polymorphism? If Yes or No, Justify your Answer.
MISS
FIZZAH SOHAIL
QUESTION # 01:
Figure out the type of polymorphism is method overloading and method
overriding respectively.
ANSWER : Polymorphism in Java has two types: Compile time polymorphism (static binding)
and Runtime polymorphism (dynamic binding). Method overloading is an example of
static polymorphism, while method overriding is an example of dynamic polymorphism.
Polymorphism means more than one form, same object performing different operations according
to the requirement.
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.
To achieve the polymorphism every developer must use the same method names in the project.
}
}
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
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.