MCQ – Java Polymorphism

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?

  1. Method overloading
  2. Constructor overloading
  3. Method overriding
  4. All the above

Answer: 4

Explanation: All mentioned features come under polymorphism in java oop.


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) {
	}
}
  1. Method overloading
  2. Constructor overloading
  3. Method overriding
  4. 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?

  1. Method overloading
  2. Constructor overloading
  3. Method overriding
  4. 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?

  1. Method overloading
  2. Constructor overloading
  3. Method overriding
  4. Both A and B
  5. 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();
	}

}
  1. Father’s Car
  2. Son’s Car
  3. There is an ambiguity, so no one Car
  4. 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.


Related Posts