This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Override - Overload - quick question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Override - Overload - quick question" Watch "Override - Overload - quick question" New topic
Author

Override - Overload - quick question

Tommaso Nuccio
Ranch Hand

Joined: Dec 11, 2006
Posts: 66
Hi there,

without using a compiler, will this compile:


If not, where is the problem and why?!

I am curious to read answers.


Ciao,<br /> Tommaso<br /> <br />~*~*~*~<br />There are 10 types of people, those who understand binary and those who don't.
Meena R. Krishnan
Ranch Hand

Joined: Aug 13, 2006
Posts: 178
I don't think this will compile. Overloaded methods must differ in their arguments and not just the return type. First and third methods have the same set of arguments and only different in their return type.
m ali
Ranch Hand

Joined: Apr 12, 2007
Posts: 49
Hi Tommasso,

This wont compile. The compiler will not resolve which amethod is calling with the same arguements - int and String. Am I right?

Thanks.
Tommaso Nuccio
Ranch Hand

Joined: Dec 11, 2006
Posts: 66
Yeah,

you are both right.
The trick here is that the return type doesn't make a override!

Thanks.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hey
Hey Tommaso,

Originally posted by Tommaso Nuccio,



without using a compiler, will this compile:

code:


class Rid{
public void amethod(int i, String s){}
public void amethod(String s, int i){}
public int amethod(int i, String s){}
}


See the question what you ask,
without using a compiler



cmbhatt


cmbhatt
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Tommaso Nuccio:
Yeah,

you are both right.
The trick here is that the return type doesn't make a override!

Thanks.


Override? There is nothing being overridden here. This is about overloading.
[ April 16, 2007: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Tommaso Nuccio
Ranch Hand

Joined: Dec 11, 2006
Posts: 66
Barry,

you are right.
Sorry, that was a typo.

Regards.
Gaurav Pavan Kumar Jain
Ranch Hand

Joined: Mar 19, 2007
Posts: 168
Hi Tommaso

Whenever you want to overload a method you must take care of parameters you are passing. All the parameter you are passing in overloading a method must be different in each method.


Best Of Luck
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Override - Overload - quick question
 
Similar Threads
overloading
overloaded??
overloaded methods
Overloading
Marcus Green - Qn : 23 - Doubt