MCQ – Java Polymorphism


Q) Which is runtime polymorphism in java oops?

  1. Method overloading
  2. Method overriding
  3. Constructor overloading
  4. None

Answer: 2
Explanation: Method overriding is the run time polymorphism as the methods call get resolved at run time. Compiler will not be able to decide which object’s method to call at compile time.
Recommend reading about run time polymorphism for better understanding. It has been described nicely with example.


Q)In below java program, the class Circle implements the interface Shape. Which polymorphism concept has been applied here?

interface Shape {
	void area();
}

class Circle implements Shape {

	public void area() {

	}
}
  1. Method overloading
  2. Method overriding
  3. No polymorphism

Answer: 2
Explanation: A class implements an interface in java and override all the methods resides in the interface. Note that interface does not have implemented method and whoever class implements it, class must override and give its own definition

You can read interface with example in java programming in detail.


Q) Which polymorphism feature is related to parent and child class relationship in java.

  1. Method overloading
  2. Constructor overloading
  3. Method overriding
  4. Both A and B
  5. Bothe A and C

Answer: 3
Explanation: Method overriding feature is always used in parent child relationship in inheritance in java. Whatever, the relationship is base class to derived class or interface to class.


Q) Which method of base class X, the derived class Y cannot override?

class X {
	
	final public void m1() {

	}

	public void m2() {

	}

}
class Y extends X {

	// override?
}
  1. m1()
  2. m2()
  3. Both m1() and m2() can override
  4. No method can override

Answer: 1

Explanation: Derive class Y cannot Override base class method m1() as this method is declared as final.
final method in java cannot be overridden by any derived class.


Q) Which are true statements regarding polymorphism concept?

  1. Method overloading is used in same class only
  2. Constructor overloading is used in same class only
  3. Method overriding is used in base class and derived class
  4. All

Answer: 4
Explanation: Method overloading – multiple methods with same name and different number of arguments or data types are written in the same class only. Similar is with constructor overloading. By the way, constructor of a class in java programming cannot be written in other classes. Method overriding is used in inheritance.


Related Posts