Sample Questions
 

 

1. Which two create an instance of an array? (Choose two.)

A. int[ ] ia = new int[15];
B. float fa = new float[20];
C. char[ ] ca = "Some String";
D. Object oa = new float[20];

2. Given:

public class ArrayTest {
public static void main(String[ ] args){
float f1[ ], f[ ];
f1 = new float[10];
f = f1;
System.out.println("f[0] = " + f[0]);
} }

What is the result?

A. It prints f2[0] = 0.0
B. It prints f2[0] = NaN
C. An error at ‘f2 = f1;’ causes compile to fail.
D. An error at ‘System.out.println("f2[0] = " + f2[0]);’ causes compile to fail.

3. Which two cause a compiler error? (Choose two.)

A. int[ ] scores = {3, 5, 7};
B. int [ ][ ] scores = {2,7,6}, {9,3,45};
C. String cats[ ] = {"Fluffy", "Spot", "Zeus"};
D. boolean results[ ] = new boolean [3] {true, false, true};
 

4. Which three form part of correct array declarations? (Choose three.)

A. public int a [ ]
B. static int [ ] a
C. public [ ] int a
D. public final int [ ] a
 

5. Which two cause a compiler error? (Choose two.)

A. float[ ] f = new float(3);
B. float f2[ ] = new float[ ];
C. float[ ]f1 = new float[3];
D. float f3[ ] = new float[3];


Answers:    1 (A,D), 2 (A), 3 (B,D), 4 (A,B,D), 5 (A,B)

More Practice Test at:

https://www.vskills.in/practice/quiz/Core-Java

 

Apply for Certification

https://www.vskills.in/certification/Certified-Core-Java-Developer