You are on page 1of 7

1.

Which of the following method signatures is a valid declaration of an entry point in a

Java application?

A. public void main(String[] args)

B. public static void main()

C. private static void start(String[] mydata)

D. public static final void main(String[] mydata)

2. Which variables have a scope limited to a method?

A. Interface variables

B. Class variables

C. Instance variables

D. Local variables

3) Which of the following is not a valid code comment in Java?

A. // Add 5 to the result

B. /*** TODO: Fix bug 12312 ***/

C. # Add configuration value

D. /* Read file from system ****/

4) What is the result of compiling and executing the following class?

1: public class ParkRanger {

2: int birds = 10;

3: public static void main(String[] data) {

4: int trees = 5;

5: System.out.print(trees+birds);

6: }

7: }
A. It does not compile.

B. It compiles but throws an exception at runtime.

C. It compiles and outputs 5.

D. It compiles and outputs 15.

5)What is the result of compiling and executing the following class?


package sports;

public class Bicycle {

String color = "red";

private void printColor(String color) {

color = "purple";

System.out.print(color);

public static void main(String[] rider) {

new Bicycle().printColor("blue");

A. red

B. purple

C. blue

D. It does not compile.

6. Which of the following is not a valid variable name?

A. _blue

B. 2blue

C. blue$

D. Blue

7. Which of these class names best follows standard Java naming conventions?

A. fooBar

B. FooBar

C. FOO_BAR

D. F_o_o_B_a_r

8) What is the output of the following?

package beach;

public class Sand {

public Sand() {
System.out.print("a");

public void Sand() {

System.out.print("b");

public void run() {

new Sand();

Sand();

public static void main(String... args) {

new Sand().run();

A. a

B. ab

C. aab

D. None of the above

9) Which of the following variable types is not permitted in a switch statement?

A. String

B. double

C. int

D. char

10) What is the value of thatNumber after the execution of the following code snippet?

long thatNumber = 5 >= 5 ? 1+2 : 1*1;

if(++thatNumber < 4)

thatNumber += 1;

A. 3

B. 4

C. 5
D. The answer cannot be determined until runtime.

11) What is the output of the following application?

package restaurant;

public class Pieces {

public static void main(String[] info) {

int flair = 15;

if(flair >= 15 && flair < 37) {

System.out.print("Not enough");

} if(flair==37) {

System.out.print("Just right");

} else {

System.out.print("Too many");

A. Not enough

B. Just right

C. Too many

D. None of the above

12) What is the output of the following application?

package schedule;

public class PrintWeek {

public static final void main(String[] days) {

System.out.print(5 + 6 + "7" + 8 + 9);

A. 56789

B. 11789

C. 11717
D. The code does not compile.

13) What is the output of the following application?

package mode;

public class Transportation {

public static String travel(int distance) {

return distance<1000 ? "train" : 10;

public static void main(String[] answer) {

System.out.print(travel(500));

A. train

B. 10

C. The code does not compile.

D. The code compiles but throws an exception at runtime

14) How many lines does the following code output?

String[] days = new String[] { "Sunday", "Monday", "Tuesday",

"Wednesday", "Thursday", "Friday", "Saturday" };

for (int i = 0; i < days.length; i++)

System.out.println(days[i]);

A. Six

B. Seven

C. The code does not compile.

D. The code compiles but throws an exception at runtime

15)Which type of loop is best known for its boolean condition that controls entry to the loop?

A. do-while loop

B. for (traditional)

C. for-each

D. while
16) Which type of loop is best known for using an index or counter?

A. do-while loop

B. for (traditional)

C. for-each

D. while

17Which of the following is equivalent to this code snippet given an array of String objects?

for (int i=0; i<fun.length; i++)

System.out.println(fun[i]);

A. for (String f = fun) System.out.println(f);

B. for (String f : fun) System.out.println(f);

C. for (String = fun) System.out.println(it);

D. None of the above

18) What does the following code output?

int singer = 0;

while (singer > 0)

System.out.println(singer++);

A. 0

B. The code does not compile.

C. The loops completes with no output.

D. This is an infinite loop

19)What is the output of the following?

boolean balloonInflated = false;

do {

if (!balloonInflated) {

balloonInflated = true;

System.out.print("inflate-");

} while (! balloonInflated);

System.out.println("done");
A. done

B. inflate-done

C. The code does not compile.

D. This is an infinite loop

20) What is the output of the following?

12: int result = 8;

13: for: while (result > 7) {

14: result++;

15: do {

16: result--;

17: } while (result > 5);

18: break for;

19: }

20: System.out.println(result);

A. 5

B. 8

C. The code does not compile.

D. The code compiles but throws an exception at runtime.

You might also like