package pkg;
class a{}
public class p102 {
static void printFun1(Object[] args) {// Object
for (Object tmp:args)
System.out.print(tmp+",");
System.out.println();
}
static void printFun2(int k,Object...args) {//Object 2
System.out.print("K="+k+" ");
for (Object obj:args) {
System.out.print(obj+" ");
}
System.out.println();
}
static void printFun3(int j,String...args) {//String int double ... all is OK
System.out.print("J="+j+" ");
for (String str:args) {
System.out.print(str+"/ ");
}
}
public static void main(String[] args) {
//func 1
printFun1(new Object[]{new Integer(15),new Float(2.71828),new Double(3.14),"Unbelivable"});
printFun1(new Object[]{"Here","you","see","six","strings","now!",new Integer(9527)});
printFun1(new Object[]{new a(),new a()});
System.out.println("------------ CUT LINE ------------\n");
//func 2
printFun2(886,new Object[] {1,1,2,"object is so",5,8,13,3.14,"flexible"});
printFun2(1,new Object[] {2.1,2.3,4,5,"abc"});
System.out.println("------------ CUT LINE ------------\n");
//func 3
printFun3(100,new String[] {"Tom","cat","&","jenny","mouse"});
//printFun3(100,new String[] {"Tom","cat",100,"jenny","mouse"});//ERROR!
}
}
OUTPUT:
15,2.71828,3.14,Unbelivable,
Here,you,see,six,strings,now!,9527,
pkg.a@15db9742,pkg.a@6d06d69c,
------------ CUT LINE ------------
K=886 1 1 2 object is so 5 8 13 3.14 flexible
K=1 2.1 2.3 4 5 abc
------------ CUT LINE ------------
J=100 Tom/ cat/ &/ jenny/ mouse/