Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views1 page

0 - Javamcq Part1 32

The document presents a series of Java programming questions and answers related to arrays and their properties. It covers topics such as output of specific code snippets, characteristics of Java arrays, and valid array declarations. The answers provided indicate the correct options for each question, highlighting key concepts in Java programming.

Uploaded by

Priyansh Gangani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

0 - Javamcq Part1 32

The document presents a series of Java programming questions and answers related to arrays and their properties. It covers topics such as output of specific code snippets, characteristics of Java arrays, and valid array declarations. The answers provided indicate the correct options for each question, highlighting key concepts in Java programming.

Uploaded by

Priyansh Gangani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

15-what is the output of this program?

Class output {
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < arr.length - 2; ++i)
system.out.println(arr[i] + " ");
}
}
a) 1 2
b) 1 2 3
c) 1 2 3 4
d) 1 2 3 4 5
answer: b
16. in java arrays are
a.objects
b.object references
c.primitive data type
d. none of this
ans: a
17. which one of the following is a valid statement?
a.char[] c = new char();
b.char[] c = new char[5];
c.char[] c = new char(4);
d.char[] c = new char[];
ans: b

18-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);
}
}
a.0
b.compilation error, arrays cannot be initialized to zero size.
c.compilation error, it is a.length() not a.length
d.none of the above
ans: a

19-what will be the output?


public Class test{
public static void main(String[] args){
int[] x = new int[3];
system.out.println("x[0] is " + x[0]);
}
}
a.the program has a compile error because the size of the array wasn't specified when
declaring the array.
b.the program has a runtime error because the array elements are not initialized.

You might also like