• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is Return Type Included in Method Signature ?

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks all of you.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic