This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's the output? overload?

 
kwan Jang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Super{
public int getLength(){ return 4;}
}
public class Sub extends Super{
public long getLength(){ return 5;}
public static void main(String args[]){

Super sooper = new Super();
Sub sub=new Sub();
System.out.println(sooper.getLength()+","+sub.getLength());

}
}


a:4,4 b:4,5 c:5,4 d:5,5 e:compilation fails.
[ November 28, 2006: Message edited by: Barry Gaunt ]
 
Micheal John
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not overloaded. It will give you compilation error.
Since compiler thought of overriding the getLength() with different return type. For Overloading return type alone should nto be different, but also the signature..
try this
 
David A. Scott
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Additionally, it's not a valid override because the return types do differ.
 
kwan Jang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,everybody!!
 
kwan Jang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It must be overload or override,if two methods have the same name?
 
Greg L Tonn
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two or more methods could have the same name and not be Overloaded or Overriden. They call it Hidden methods and they are not very good they can cause hard to find bugs.

You cannot just look at the name of the method, you need to look at the whole method signature.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic