ULTIMATE MCQs – Multiple Choice Questions on Porlymorphism in java oops concept with Answer and Explanation to polish your concepts and help in written test in job interviews.
MCQs on Polymorphism in Java
Q) What concepts come under Polymorphism in java?
- Method overloading
- Constructor overloading
- Method overriding
- All the above
Answer: 4
Explanation: All mentioned features come under polymorphism in java oop.
- Method overloading (multiple methods with same name in a class)
- Constructor overloading (multiple constructors in a class)
- Method overriding (methods with same in base and derived class)
Q) Which polymorphism behavior do you see in below class?
class Paint {
// all methods have same name
public void Color(int x) {
}
public void Color(int x, int y) {
}
public void Color(int x, int y, int z) {
}
}
- Method overloading
- Constructor overloading
- Method overriding
- Run time polymorphism
Answer: 1
Explanation:
Method with same name with different number of arguments or same number of arguments with different data types is method overloading in java programming.
Q) Which polymorphism concept is applied to inheritance relationship in java programming?
- Method overloading
- Constructor overloading
- Method overriding
- None
Answer: 3
Explanation: Method overriding concept is related with inheritance in java. Both base and derived class contains methods with same name and signature. Read method overriding concept in java oop.
Q) Which feature comes under compile time polymorphism?
- Method overloading
- Constructor overloading
- Method overriding
- Both A and B
- Bothe A and C
Answer: 4
Method overloading, and constructor overloading come under compile time polymorphism. as compiler resolves overloaded method at compile time. in simple word, compiler can understand which overloaded method or constructor to call at compile time itself.
Read more on compile time and run time polymorphism in java with example.
Q) In below java code, whose “Car” will be called?
class Father {
public void car() {
System.out.println("Father's Car");
}
}
class Son extends Father {
public void car() {
System.out.println("Son's Car");
}
}
public class Sample {
public static void main(String[] args) {
Son john = new Son();
john.car();
}
}
- Father’s Car
- Son’s Car
- There is an ambiguity, so no one Car
- Compiler Error
Answer: 2
Explanation: Since, both Father class and Son class contain car () method, So, on object creation of Son class, the son’s car() method will be called. Son has overrides car method of base class Father.
Note that if son does not contain car method, then father class car () method will be called.