A method is defined in a class as : void processUser(int i) { } If this method is overriden in a sub class, (a) the new method should return int (b) the new method can return any type of values (c) the argument list of new method should exactly match that of overriden method (d) the return type of new method should exactly match that of overriden method

Showing Answers 1 - 6 of 6 Answers

Shashidhar Mahavadi

  • Jun 8th, 2005
 

I hope this Answer is correct..I welcome your valueable feedback. 
 
In method overriding, the subclass completely replace the functionality in subclass, the method must have the same signature as the version in the base class. I mean to say the return type should be the same. if the return type is different, with same name and signature then the compiler may recognise this as a faulty attempt to overload the method then overriding.

  Was this answer useful?  Yes

vasu

  • Feb 3rd, 2006
 

The answers are  both c and D

(c) the argument list of new method should exactly match that of overriden method
(d) the return type of new method should exactly match that of overriden method

Shantanu

  • Apr 26th, 2006
 

for Overridding method, the signature of overridden method should match exactly. i.e. the return type of method as well as arguments(parameters) must match exactly in number,sequence and Class Type.

Hence the answer is option (c) and (d)

  Was this answer useful?  Yes

Purnima

  • Jun 6th, 2006
 

In an overriden method the signature should be same so the answer is c & d

  Was this answer useful?  Yes

Explaination

A: new method can have int return type but argument list should be changed. But it is not Compulsory to have return type int. So a is wrong for this question.

B: yes it can return any type of value but argument list should be changed.

C: no, new method can have different argument list.

D: yes it should match with overiden method if argument list is SAME as overiden method.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions