Sail E0 Webinar
Question


What is the output of this program?


What is the output of this program?
class Output {
public static void main(String args[])
{
int a1[] = new int[10];
int a2[] = {1, 2, 3, 4, 5};
System.out.println(a1.length + " " + a2.length);
}
}
Options:
A .  10 5
B .  5 10
C .  0 10
D .  0 5
Answer: Option A

 Arrays in java are implemented as objects, they contain an attribute that is length which 

contains the number of elements that can be stored in the array. Hence a1.length gives 

10 and a2.length gives 5.

output:
$ javac Output.java
$ java Output
10 5



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers