Object-Oriented Programming · Question 10 · Medium

Which pair of method declarations CANNOT both appear in the same Java class?

  1. int f(int a) and int f(double a)
  2. int f(int a) and double f(int a)
  3. int f(int a) and int f(int a, int b)
  4. void f(String s) and void f(Object o)
Answer and explanation

Answer: B. int f(int a) and double f(int a)

Explanation: Overloads must differ in their parameter lists. The two methods in this option differ only in return type, so they have the same signature and the code does not compile.

Previous: In C++, how is the "diamond problem" (two copies of a common base class… · Next: What is printed when new C() is executed?

Practise object-oriented programming

Try a fresh set of object-oriented programming questions with an explanation after every answer, free and without signing up: Object-Oriented Programming practice. Or sit a full placement mock test.

More object-oriented programming questions

More technical & programming practice

DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge