Hi all,
consider below code:
public class Bertha {
static String s = "";
public static void main(String[] args) {
int x=4;
Boolean y = true;
short[] sa = {1,2,3};
doStuff(x,y);
doStuff(x);
doStuff(sa,sa);
System.out.println(s);
}
static void doStuff(Object o){
s += "1";
}
static void doStuff(Object... o){
s += "2";
}
static void doStuff(Integer... i){
s += "3";
}
static void doStuff(Long L){
s += "4";
}
}
output : 212
here i have doubt that how Object... o have been called for doStuff(x,y) and for doStuff(sa,sa);
could anyone explain what goes around here.
Thanks in advance.
surya55
0
Newbie Poster
Recommended Answers
Jump to Postan array in Java is an Object. not an Integer, but still an Object.
so, you pass two instances of Object to doStuff, and the only method you have capable of dealing with this is:static void doStuff(Object... o){ s += "2"; }
All 2 Replies
stultuske
1,116
Posting Maven
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.