A method is defined in a class as : void processUser(int i) { } If this method is overriden in a sub class,_

  1. the new method should return int

  2. the new method can return any type of values

  3. the argument list of new method should exactly match that of overriden method

  4. the return type of new method should exactly match that of overriden method


Correct Option: C

AI Explanation

To answer this question, we need to understand the concept of method overriding in Java.

Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its parent class. When overriding a method, certain rules must be followed. Let's go through each option to understand why it is correct or incorrect:

Option A) The new method should return int - This option is incorrect. The return type of the overriding method can be a subtype of the return type of the overridden method, but it cannot be a different type.

Option B) The new method can return any type of values - This option is incorrect. The return type of the overriding method should be covariant with the return type of the overridden method. In other words, it should be the same type or a subtype of the return type of the overridden method.

Option C) The argument list of the new method should exactly match that of the overridden method - This option is correct. The argument list of the overriding method should be the same as the argument list of the overridden method. This ensures that the method signature remains the same.

Option D) The return type of the new method should exactly match that of the overridden method - This option is incorrect. As mentioned earlier, the return type of the overriding method can be a subtype of the return type of the overridden method, but it cannot be a different type.

The correct answer is C. The argument list of the new method should exactly match that of the overridden method. This ensures that the method signature remains the same.

Therefore, the correct answer is option C.

Find more quizzes: