Question
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);
}
}
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);
}
}
Answer: Option A
Was this answer helpful ?
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 ?
Submit Solution