This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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.
 
Consider Paul's rocket mass heater.
 
subject: what's the output? overload?
 
Similar Threads
Unable to run the following program
Question from examlab practice test 2
overriding