File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding question

 
Don Bosco
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the derived class the two methods are overloaded, not overriden.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic