Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Return Type Included in Method Signature ?

 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Can any one tell me return type included in method signature or not.
if yes then
Suppose a case when
Two Classes are there A & B.
B extends A.
Now

class classBase{
public A method (){
.........
...........
return new A();
}
}
class classChild extends classBase{
public B method(){
.........
...........
return new B();

}
}
The Question is
In this case Overriding is happening or not.
[ June 30, 2006: Message edited by: vijay saraf ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, this is not valid. Return type has to be the same.
 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it means return type should exactly be the same as in base class's method.
but i have read somewhere that signature means
method name and parameter list.....excluding return type.is it ok??
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A method's signature is its name and the number and the type of its arguments. The method return type, method modifiers, and declared thrown exceptions have no effect on the method signature.
 
S Thiyanesh
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i have read somewhere that signature means
method name and parameter list.....excluding return type.is it ok??

This is called as Covariant return types included from Java 5.


This is a perfect override for SCJP 1.5 but a compiler error for SCJP 1.4.
 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all of you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic