Forums Register Login

method overloading

+Pie Number of slices to send: Send
//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 */
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you Guys.
It helped me .
Hold that thought. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 436 times.
Similar Threads
Regarding String
Function overloading
overload question
null as parameter
overloading
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:13:08.