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)?
- A train travels 40% faster than a car. Both start from point A at the same time and reach point B, 140 km away at the same time. On the way the train takes 25 minutes for stopping at the stations. What is the speed (in km/hr) of the train?
- Three measuring rods are of length 120 cm, 100 cm and 150 cm. Find the least length of the fence that can be measure an exact number of times, using any of the rods. How many times each rod will be used to measure the length of the fence?