• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clarification on dynamic binding.  RSS feed

 
merlin bar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name and parameter type list for a method is called the method's signature. For example, f(int) and f(String) are two methods with the smae name but different signatures.
If you define a method in a subclass that has the same signature as a superclass method, then you override that method. However, the return type is not part of the signatuer.
Therefore, you cannot define a method int f(String) in a super class and a method void f(String) in a subclass.

Is the last line (bold) in error? Does it mean I cannot create this method in the context of overloading, or that I cannot create this method at all?
regards,
merlin
[ November 25, 2003: Message edited by: Jim Yingst ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the last line (bold) in error? Does it mean I cannot create this method in the context of overloading, or that I cannot create this method at all?
It means you can't create the method at all. However there is a slight error here - the superclass method might be private, in which case there's no problem. Aside from that, though, it's correct.
 
lekha phijo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a method int f(int k) in a class.
1 .Then u cannot overload this method with float f(int k).
you can overload this method with int f(float k).
2. You cannot override( redefine ) in the sub class as float f(int k)
compiler forces u to have the return type as int.Which means when u r redefining method f(int k) return type has to be same.
RETURN TYPE IS NOT A PART OF METHOD SIGNATURE
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!