Consider the following code:
public class Main{ public void test (){ test1 (10); //1 test1 (10, 20); //2 } /*from w w w. j av a 2 s . com*/ public static void main (String [] args){ new Main ().test (); } //insert method here. }
Which of the following lines can be added independently to the above class so that it will run without any errors or exceptions?
Select 2 options
Correct Options are : B C
A var-arg parameter of type T is same as an array of type T.
class TestClass { String m1 (int [] i) { return ""+i.length; } String m2 (int... i) { return ""+i.length; } }
javap
TestClass
produces this:
java.lang.String m1 (int []); java.lang.String m2 (int []);
Conversely, the following code will not compile:
class TestClass { String m1 (int [] i) { return ""+i.length; } String m1 (int... i) { return ""+i.length; } }