Recall & Review
beginner
What is compile-time polymorphism in Java?
Compile-time polymorphism is when the method to be called is decided during the compilation of the program. It is also called method overloading.
Click to reveal answer
beginner
How does method overloading demonstrate compile-time polymorphism?
Method overloading allows multiple methods with the same name but different parameters. The compiler decides which method to call based on the arguments used.
Click to reveal answer
intermediate
Can compile-time polymorphism be achieved using method overriding?
No, method overriding is runtime polymorphism because the method to call is decided during program execution, not at compile time.
Click to reveal answer
intermediate
What are the requirements for method overloading in Java?
Methods must have the same name but differ in the number, type, or order of parameters. Return type alone is not enough to overload a method.
Click to reveal answer
beginner
Example of compile-time polymorphism using method overloading:
class Calculator {
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
}
The compiler chooses which add method to call based on argument types.Click to reveal answer
What decides which overloaded method to call in Java?
✗ Incorrect
Compile-time polymorphism means the compiler decides which method to call based on the method's parameters.
Which of the following is NOT a valid way to overload a method?
✗ Incorrect
Changing only the return type does not overload a method because the compiler cannot distinguish methods by return type alone.
Compile-time polymorphism is also known as:
✗ Incorrect
Method overloading is compile-time polymorphism because the method call is resolved during compilation.
Which polymorphism type is determined at runtime?
✗ Incorrect
Runtime polymorphism is when the method to call is decided during program execution, such as with method overriding.
In Java, which keyword is NOT related to compile-time polymorphism?
✗ Incorrect
The '@Override' annotation relates to method overriding (runtime polymorphism), not compile-time polymorphism.
Explain compile-time polymorphism and how Java achieves it.
Think about how Java chooses which method to run before the program starts.
You got /3 concepts.
Describe the difference between compile-time and runtime polymorphism with examples.
One is decided by the compiler, the other by the program while running.
You got /3 concepts.