File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding question" Watch "Overriding question" New topic
Author

Overriding question

Don Bosco
Ranch Hand

Joined: Oct 31, 2002
Posts: 108
class Base{
public void method(String s){ }
}
class Derived extends Base{
public void method(Object o){ }
}
Are we overriding the method()??? I know that the signature should me same for overriding.
Please comment on this.


SCJP 1.4<p>Wingardium Leviosa!!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
No, you are just defining a method in the subclass which will not be available through a base object reference. It just happens to have the same name as that defined in the base class, that's all.
However,

will not compile because the compiler can not resolve the ambiguity of calling Base.method(String) or Derived.method(Object).
-Barry
[ November 01, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
In the derived class the two methods are overloaded, not overriden.


SCJP2. Please Indent your code using UBB Code
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Jose, I hesitated to use the term overloaded because the two methods are defined in different classes.
I'll have to check that out I guess
-Barry
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
JLS 8.4.7 to the rescue:

If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but different signatures, then the method name is said to be overloaded.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I wasn't doubting you Jose! I stuck it in the todo box
Ok then, quick, what's JLS 12.1.3 say? C'mon no cheating, don't look...
-Barry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding question
 
Similar Threads
Method Overloading
Doubt about access rules for inherited static method.
Overriding/overloading
Inheritance
Using Reflection to call super class method