File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what's the output? overload? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what Watch "what New topic
Author

what's the output? overload?

kwan Jang
Greenhorn

Joined: Sep 24, 2006
Posts: 16
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

Joined: Nov 01, 2006
Posts: 344
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


Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
David A. Scott
Ranch Hand

Joined: Apr 13, 2006
Posts: 55
Additionally, it's not a valid override because the return types do differ.
kwan Jang
Greenhorn

Joined: Sep 24, 2006
Posts: 16
thanks,everybody!!
kwan Jang
Greenhorn

Joined: Sep 24, 2006
Posts: 16
It must be overload or override,if two methods have the same name?
Greg L Tonn
Ranch Hand

Joined: Nov 27, 2006
Posts: 52
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's the output? overload?