Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overloaded-overriden

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

O/P : ABC

Class B extends class A and Class C extends class B, therefore method m1() is overdidden right?.
But according to the output, method m1() is overloaded. Some one please explain how method m1() is overloaded and not overridden.
 
Rajasekar Elango
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here the method m1() in subclasses B and C overloads the method m1() inherited from its parent class A.

Overridding methods should have same method signature, both method parameters and return type should be same.

Thanks,
Raja
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
method parameters are different.so it is method overloading.Overridden method signature must be same.

Note:
In Java 1.5 the return type of the overriding method can be different.
When you override a method, the declared return type can be any subclass of the the class returned by the original method. Currently, the method signature of an overriding method has to match exactly that of the method that it is overriding, including the return type.

http://forum.java.sun.com/thread.jspa?threadID=477074&messageID=2215964
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic