• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

method overloading

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 */
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Guys.
It helped me .
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic