aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method overloading" Watch "method overloading" New topic
Author

method overloading

Tony reedy
Greenhorn

Joined: Jan 11, 2002
Posts: 21
//partI
public class Aquestion
{
Public void method(Object o)
{
System.out.println("object version");
}
Public void method(String s)
{
System.out.println("string version");
}
public static void main(String[] args)
{
AQuestion q =new AQuestion();
q.method(null);
}
}
//part II
public class Aquestion
{
Public void method(StringBuffer sb)
{
System.out.println("string buffer version");
}
Public void method(String s)
{
System.out.println("string version");
}
public static void main(String[] args)
{
AQuestion q =new AQuestion();
q.method(null);
}
}
/* 1)why will ther be a compile time error in partII and not in PartI.
2)In PartI how does the compiler know which method() to call when both mehtods can take null value as argument */
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Tony,
Thist topic has been convered in depth previously. Try and use the search function on the upper right of this forum before asking questions. You will learn alot and probably answer your question.
See this link for a good explanation.
Regards,
Manfred.
Tony reedy
Greenhorn

Joined: Jan 11, 2002
Posts: 21
Thank you Guys.
It helped me .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method overloading