+ 1
Is it possible to initialize two variables(same datatype and different datatype) in one constructor?
3 odpowiedzi
+ 3
Are you looking for varargs?
public class Program{
// varargs in constructor
public Program(int... i) {
System.out.println("Constructor:");
for (int j=0; j<i.length; j++)
System.out.println(i[j]);
}
public static void main(String[] args) {
Program prog = new Program (1,2,3);
Program prog1= new Program (4,5,6,7,8);
}
}
+ 2
Yes we can!
public Program(int i, String str, double d) {
}
+ 1
Thank you for your answer Tashi. You had helped me with one question. Another question that is to be answered is can we initialize different datatype variables in the same constructor?