Final method

Having said a final method can be overloaded(default in d same class) plz explain me if there is anything missing in this code ?

class Base {
public final doSomething(Object o) {
System.out.println("Object");
}
}
class Derived extends Base {
public doSomething(Integer i) {
System.out.println("Int");
}
}
public static void main(String[] args) {
Base b = new Base();
Base d = new Derived();
b.doSomething(new Integer(0));
d.doSomething(new Integer(0));
}
This will print:
Object
Object
MY DOUBT IS IN THE DERIVED CLASS METHOD ! IS DER D FINAL KEYWORD MISSING ??

Questions by gova007

Showing Answers 1 - 9 of 9 Answers

neetub

  • Feb 2nd, 2012
 

No there is no coding mistake. Only there has to be return type for method doSomething() as void.

  Was this answer useful?  Yes

santhosh

  • Feb 23rd, 2012
 

In the main method,you simply change the "base d" as "Derived d" you get "object" and "int" as a output.also returned type is required.

  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