Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method overloading

 
Tony reedy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Guys.
It helped me .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic