0
0
What will be the output of the program?public class Test{ public static void main(String [] args){ String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); }}and the command-line invocation
What will be the output of the program?public class Test{ public static void main(String [] args){ String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); }}and the command-line invocation is C:Java> java Test 1 2 3 4
A). args[2] = 2
B). args[2] = 3
C). args[2] = null
D). An exception is thrown at runtime.
This Question has 1 answers.
An exception is thrown at runtime.
An exception is thrown because in the code String s4 = args[4];, the array index (the fifth element) is out of the bounds. The exception thrown is the ArrayIndexOutOfBoundsException.
Similar Questions
- Two types of rice (type 1 and type 2) were mixed in the respective ratio of 1 : 3. The mixture was then sold @ 75.60 per kg to gain a profit of 20%. If the price of type 1 rice is Rs. 75 per kg, what is the price of type 2 price per kg?
- Two towns P & Q are 275 km apart. A motorcycle rider starts from P towards Q at 8 a.m. at the speed of 25 km/hr. Another rider starts from Q towards P at 9 a.m. at the speed of 20 km/hr. Find at what time they will cross each other?
- Train A takes 45 minutes more than train B to travel a distance of 450 km. Due to engine trouble speed of train B falls by a quarter, so it takes 30 minutes more than Train A to complete the same journey. What is the speed of Train A (in km/hr)?
- X and Y are two alloys which are prepared by mixing zinc and aluminium in the ratio of 1 : 4 and 11 : 8 respectively. If equal quantities of alloys are melted to form a third alloy Z then what is the ratio of zinc and aluminium in alloy Z?
- An alloy has Iron, Silver and Bronze in the ratio 7 : 2 : 3. Another alloy has Silver and Bronze in ratio 1 : 2. In what ratio should the two mixtures be mixed so that the ratio of Iron and Silver in resultant mixture is 5 : 3?