Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Overriding question

 
Ranch Hand
Posts: 108
  • 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.
 
Ranch Hand
Posts: 7729
  • 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 ]
 
Ranch Hand
Posts: 2120
  • 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
  • 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
  • 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
  • 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
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!