1 What is polymorphism? 2. What is dynamic binding? What is late binding? Give a
ID: 3911140 • Letter: 1
Question
1 What is polymorphism? 2. What is dynamic binding? What is late binding? Give an example of each. 3 Is overloading a method name an example of polymorphism? 4 In the following code, will the two invocations of writeOutput produce the same output on the screen or not? Person person- new Student("Sam, 999); person.writeOutput): personnew Undergraduate("Sam", 999,1); person.writeOutput0: 5. In the following code, which definition of writeOutput is invoked? Undergraduate ug-new Undergraduate("Sam", 999, 1); Person p (Person) ug; p.writeOutput):Explanation / Answer
Q1
Polymorphism refers to the ability of a variable, function or object to take on multiple forms.
Q2
Dynamic Binding and Late binding are same. I think what you want to ask difference in between is Static(early) and Dynamic(late) binding
Static Binding: When type of the object is determined at compile time
eg:
class Cat{
private void eat(){System.out.println("Cat is eating...");}
public static void main(String args[]){
Cat c1=new Cat();
c1.eat();
}
}
Dynamic Binding: When type of the object is determined at run-time
Eg:
class Animal{
void eat(){System.out.println("Animal is eating...");}
}
class Cat extends Animal{
void eat(){System.out.println("Cat is eating...");}
public static void main(String args[]){
Animal a=new Cat();
a.eat();
}
}
Q3
Yes it is known as compile time polymorphism
Q4
No as the implementation might be different
Q5
The Person class method will be invoked
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.