?
What is the result of compiling and running the following code?
What is the result of compiling and running the following code?
public class Test{
public static void main(String[] args){
int[] a = new int[0];
System.out.print(a.length);
}
}
public class Test{
public static void main(String[] args){
int[] a = new int[0];
System.out.print(a.length);
}
}
Answer & Solution
Correct Answer:
Option
A
Step 1:
Declare a public class named
Step 2:
Define the
Step 3:
Declare an array variable
Step 4:
Initialize the array
Step 5:
Print the length of the array
Therefore, when you compile and run the code, the output will be:
This output corresponds to the length of the array
Declare a public class named
Test.Step 2:
Define the
main method with the public and static modifiers and a parameter of type String array named args.Step 3:
Declare an array variable
a of type int[].Step 4:
Initialize the array
a with a size of 0 using the new keyword.Step 5:
Print the length of the array
a using the length property.Therefore, when you compile and run the code, the output will be:
0This output corresponds to the length of the array
a, which is 0.
Join the Discussion
Login to post a comment or share your explanation.
Login