0
0
Javaprogramming~5 mins

Compile-time polymorphism in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe programmer manually
BThe JVM at runtime
CThe operating system
DThe compiler based on method parameters
Which of the following is NOT a valid way to overload a method?
AChanging only the return type
BChanging the number of parameters
CChanging the order of parameters
DChanging the type of parameters
Compile-time polymorphism is also known as:
AMethod overloading
BMethod overriding
CDynamic binding
DInheritance
Which polymorphism type is determined at runtime?
AMethod overloading
BRuntime polymorphism
CCompile-time polymorphism
DStatic polymorphism
In Java, which keyword is NOT related to compile-time polymorphism?
Astatic
Bfinal
C@Override
Dpublic
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.