wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CPT 236 Final Exam Review

Total questions: 203

Worksheet time: 3hrs 2mins

Name
Class
Date
1.

________ contains predefined classes and interfaces for developing Java programs.

a)

Java language specification

b)

Java API

c)

Java JDK

d)

Java IDE

2.

____________ is an operating system.

a)

Java

b)

C++

c)

Windows

d)

Visual Basic

e)

Ada

3.

________ is a technical definition of the language that includes the syntax and semantics of the Java programming language.

a)

Java language specification

b)

Java API

c)

Java JDK

d)

Java IDE

4.

Which of the following statements is correct?

a)

Every line in a program must end with a semicolon.

b)

Every statement in a program must end with a semicolon.

c)

Every comment line must end with a semicolon.

d)

Every method must end with a semicolon.

e)

Every class must end with a semicolon.

5.

________ is the physical aspect of the computer that can be seen.

a)

Hardware

b)

Software

c)

Operating System

d)

Application Program

6.

The JDK command to compile a class in the file Test.java is

a)

java Test

b)
c)

javac Test.java

d)

javac Test

e)

JAVAC Test.java

7.

If a program compiles fine, but it produces incorrect result, then the program suffers __________.

a)

a compilation error

b)

a runtime error

c)

a logic error

8.

The extension name of a Java source code file is

a)

.java

b)

.obj

c)

.class

d)

.exe

9.

Every statement in Java ends with ________.

a)

a semicolon (;)

b)

a comma (,)

c)

a period (.)

d)

an asterisk (*)

10.

Which JDK command is correct to run a Java application in ByteCode.class?

a)

java ByteCode

b)

java ByteCode.class

d)

javac ByteCode

e)

JAVAC ByteCode

11.

________ is architecture-neutral.

a)

Java

b)

C++

c)

C

d)

Ada

e)

Pascal

12.

The extension name of a Java bytecode file is

a)

.java

b)

.obj

c)

.class

d)

.exe

13.

________ is not an object-oriented programming language.

a)

Java

b)

C++

c)

C

d)

C#

e)

Python

14.

Which of the following is not permanent storage devices?

a)

floppy disk

b)

hard disk

c)

flash stick

d)

CD-ROM

e)

main memory

15.

_____________ is a program that runs on a computer to manage and control a computer's activities.

a)

Operating system

b)

Java

c)

Modem

d)

Interpreter

e)

Compiler

16.

Java compiler translates Java source code into _________.

a)

Java bytecode

b)

machine code

c)

assembly code

d)

another high-level language code

17.

The main method header is written as:

a)

public static void main(string[] args)

b)

public static void Main(String[] args)

c)

public static void main(String[] args)

d)

public static main(String[] args)

e)

public void main(String[] args)

18.

________ provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.

a)

Java language specification

b)

Java API

c)

Java JDK

d)

Java IDE

19.

__________ is the brain of a computer.

a)

Hardware

b)

CPU

c)

Memory

d)

Disk

20.

___________ translates high-level language program into machine language program.

a)

An assembler

b)

A compiler

c)

CPU

d)

The operating system

21.

How many times will the following code print "Welcome to Java"?

int count = 0;

while (count++ < 10) {

   System.out.println("Welcome to Java");

}

a)

8

b)

9

c)

10

d)

11

e)

0

22.

Do the following two statements in (I) and (II) result in the same value in sum?

(I):

for (int i = 0; i < 10; ++i) {

   sum += i;

}

(II):

for (int i = 0; i < 10; i++) {

   sum += i;

}

a)

yes

b)

no

23.

How many times will the following code print "Welcome to Java"?

int count = 0;

while (count < 10) {

   System.out.println("Welcome to Java");

   count++;

}

a)

8

b)

9

c)

10

d)

11

e)

0

24.

What is the value in count after the following loop is executed?

int count = 0;

do {

   System.out.println("Welcome to Java");

} while (count++ < 9);

System.out.println(count);

a)

8

b)

9

c)

10

d)

11

e)

0

25.

How many times is the println statement executed?

for (int i = 0; i < 10; i++)

   for (int j = 0; j < 10; j++)

     System.out.println(i * j);

a)

100

b)

20

c)

10

d)

45

26.

What is the number of iterations in the following loop?

for (int i = 1; i < n; i++) {

   // iteration

}

a)

2*n

b)

n

c)

n - 1

d)

n + 1

27.

Which of the following loops prints "Welcome to Java" 10 times?

a)

for (int count = 1; count <= 10; count++) {

   System.out.println("Welcome to Java");

}

b)

for (int count = 0; count < 10; count++) {

   System.out.println("Welcome to Java");

}

c)

for (int count = 1; count < 10; count++) {

   System.out.println("Welcome to Java");

}

d)

for (int count = 0; count <= 10; count++) {

   System.out.println("Welcome to Java");

}

28.

What is the output of the following code?

int x = 0;

while (x < 4) {

   x = x + 1;

}

System.out.println("x is " + x);

a)

x is 0

b)

x is 1

c)

x is 2

d)

x is 3

e)

x is 4

29.

What is y after the following for loop statement is executed?

int y = 0;

for (int i = 0; i < 10; ++i) {

   y += 1;

}

a)

9

b)

10

c)

11

d)

12

30.

How many times will the following code print "Welcome to Java"?

int count = 0;

do {

   System.out.println("Welcome to Java");

} while (count++ < 10);

a)

8

b)

9

c)

10

d)

11

e)

0

31.

How many times is the println statement executed?

for (int i = 0; i < 10; i++)

   for (int j = 0; j < i; j++)

     System.out.println(i * j)

a)

100

b)

20

c)

10

d)

45

32.

How many times will the following code print "Welcome to Java"?

int count = 0;

do {

   System.out.println("Welcome to Java");

   count++;

} while (count < 10);

a)

8

b)

9

c)

10

d)

11

e)

0

33.

To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy?

a)

add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0.

b)

add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.

34.

How many times will the following code print "Welcome to Java"?

int count = 0;

do {

   System.out.println("Welcome to Java");

} while (++count < 10);

a)

8

b)

9

c)

10

d)

11

e)

0

35.

Is the following loop correct?

for ( ; ; );

a)

yes

b)

no

36.

What is the output for y?

int y = 0;

for (int i = 0; i < 10; ++i) {

   y += i;

}

System.out.println(y);

a)

10

b)

11

c)

12

d)

13

e)

45

37.

What is the value of balance after the following code is executed?

int balance = 10;

while (balance >= 1) {

   if (balance < 9)

      break;

   balance = balance - 9;

}

a)

-1

b)

0

c)

1

d)

2

38.

What will be displayed when the following code is executed?

int number = 6;

while (number > 0) {

   number -= 3;

   System.out.print(number + " ");

}

a)

6 3 0

b)

6 3

c)

3 0

d)

3 0 -3

e)

0 -3

39.

The following loop displays _______________.

for (int i = 1; i <= 10; i++) {

   System.out.print(i + " ");

   i++;

}

a)

1 2 3 4 5 6 7 8 9

b)

1 2 3 4 5 6 7 8 9 10

c)

1 2 3 4 5

d)

1 3 5 7 9

e)

2 4 6 8 10

40.

What is the output after the following loop terminates?

int number = 25;

int i;

boolean isPrime = true;

for (i = 2; i < number; i++) {

   if (number % i == 0) {

      isPrime = false;

     break;

   }

}

System.out.println("i is " + i + " isPrime is " + isPrime);

a)

i is 5 isPrime is true

b)

i is 5 isPrime is false

c)

i is 6 isPrime is true

d)

i is 6 isPrime is false

41.

Does the method call in the following method cause compile errors?

public static void main(String[] args) {

   Math.pow(2, 4);

}

a)

yes

b)

no

42.

Which of the following is the best for generating random integer 0 or 1?

a)

(int)Math.random()

b)

(int)Math.random() + 1

c)

(int)(Math.random() + 0.5)

d)

(int)(Math.random() + 0.2)

e)

(int)(Math.random() + 0.8)

43.

Consider the following incomplete code:

public class Test {

   public static void main(String[] args) {

     System.out.println(f(5));

   }

   public static int f(int number) {

     // Missing body

   }

}

The missing method body should be ________.

a)

return "number";

b)

System.out.println(number);

c)

System.out.println("number");

d)

return number;

44.

Analyze the following code:

public class Test {

   public static void main(String[] args) {

     System.out.println(xMethod(5, 500L));

   }

   public static int xMethod(int n, long l) {

     System.out.println("int, long");

     return n;

   }

   public static long xMethod(long n, long l) {

     System.out.println("long, long");

     return n;

   }

}

a)

The program displays int, long followed by 5.

b)

The program displays long, long followed by 5.

c)

The program runs fine but displays things other than 5.

d)

The program does not compile because the compiler cannot distinguish which xmethod to invoke.

45.

__________ is to implement one method in the structure chart at a time from the top to the bottom.

a)

Bottom-up approach

b)

Top-down approach

c)

Bottom-up and top-down approach

d)

Stepwise refinement

46.

Which of the following should be defined as a void method?

a)

Write a method that prints integers from 1 to 100.

b)

Write a method that returns a random integer from 1 to 100.

c)

Write a method that checks whether a number is from 1 to 100.

d)

Write a method that converts an uppercase letter to lowercase.

47.

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion.

a)

a heap

b)

storage area

c)

a stack

d)

an array

48.

You should fill in the blank in the following code with ______________.

public class Test {

   public static void main(String[] args) {

     System.out.print("The grade is ");

      printGrade(78.5);

     System.out.print("The grade is ");

      printGrade(59.5);

   }

   public static __________ printGrade(double score) {

     if (score >= 90.0) {

     System.out.println('A');

     }

     else if (score >= 80.0) {

       System.out.println('B');

     }

     else if (score >= 70.0) {

       System.out.println('C');

     }

     else if (score >= 60.0) {

       System.out.println('D');

     }

     else {

       System.out.println('F');

     }

   }

}

a)

int

b)

double

c)

boolean

d)

char

e)

void

49.

Suppose your method does not return any value, which of the following keywords can be used as a return type?

a)

void

b)

int

c)

double

d)

public

e)

None of the above

50.

(int)(Math.random() * (65535 + 1)) returns a random number __________.

a)

between 1 and 65536

b)

between 1 and 65535

c)

between 0 and 65535

d)

between 0 and 65536

51.

What is k after the following block executes?

{

   int k = 2;

   nPrint("A message", k);

}

System.out.println(k);

a)

0

b)

1

c)

2

d)

k is not defined outside the block. So, the program has a compile error

52.

Does the return statement in the following method cause compile errors?

public static void main(String[] args) {

   int max = 0;

   if (max != 0)

      System.out.println(max);

   else

     return;

}

a)

yes

b)

no

53.

You should fill in the blank in the following code with ______________.

public class Test {

   public static void main(String[] args) {

     System.out.print("The grade is " + getGrade(78.5));

     System.out.print("\nThe grade is " + getGrade(59.5));

   }

   public static _________ getGrade(double score) {

     if (score >= 90.0)

        return 'A';

     else if (score >= 80.0)

        return 'B';

     else if (score >= 70.0)

        return 'C';

     else if (score >= 60.0)

        return 'D';

     else

        return 'F';

   }

}

a)

int

b)

double

c)

boolean

d)

char

e)

void

54.

All Java applications must have a method __________.

a)

public static Main(String[] args)

b)

public static Main(String args[])

c)

public static void main(String[] args)

d)

public void main(String[] args)

e)

public static main(String[] args)

55.

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as _________.

a)

method invocation

b)

pass by value

c)

pass by reference

d)

pass by name

56.

__________ is a simple but incomplete version of a method.

a)

A stub

b)

A main method

c)

A non-main method

d)

A method developed using top-down approach

57.

Arguments to methods always appear within __________.

a)

brackets

b)

parentheses

c)

curly braces

d)

quotation marks

58.

The signature of a method consists of ____________.

a)

method name

b)

method name and parameter list

c)

return type, method name, and parameter list

d)

parameter list

59.

Assume int[] t = {1, 2, 3, 4}. What is t.length?

a)

0

b)

3

c)

4

d)

5

60.

Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))?

a)

{1, 20, 30, 40, 50}

b)

[1, 20, 30, 40, 50]

c)

{1 20 30 40 50}

d)

[1 20 30 40 50]

61.

What is output of the following code:

public class Test {

   public static void main(String[] args) {

     int list[] = {1, 2, 3, 4, 5, 6};

     for (int i = 1; i < list.length; i++)

        list[i] = list[i - 1];

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

        System.out.print(list[i] + " ");

   }

}

a)

1 2 3 4 5 6

b)

2 3 4 5 6 6

c)

2 3 4 5 6 1

d)

1 1 1 1 1 1

62.

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is __________.

a)

0

b)

1

c)

2

d)

3

e)

4

63.

The JVM stores the array in an area of memory, called _______, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order.

a)

stack

b)

heap

c)

memory block

d)

dynamic memory

64.

The reverse method is defined in this section. What is list1 after executing the following statements?

int[] list1 = {1, 2, 3, 4, 5, 6};

int[] list2 = reverse(list1);

a)

list1 is 1 2 3 4 5 6

b)

list1 is 6 5 4 3 2 1

c)

list1 is 0 0 0 0 0 0

d)

list1 is 6 6 6 6 6 6

65.

In the following code, what is the output for list1?

public class Test {

   public static void main(String[] args) {

     int[] list1 = {1, 2, 3};

     int[] list2 = {1, 2, 3};

     list2 = list1;

     list1[0] = 0; list1[1] = 1; list2[2] = 2;

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

        System.out.print(list1[i] + " ");

   }

}

a)

1 2 3

b)

1 1 1

c)

0 1 2

d)

0 1 3

66.

The __________ method copies the sourceArray to the targetArray.

a)

System.copyArrays(sourceArray, 0, targetArray, 0, sourceArray.length);

b)

System.copyarrays(sourceArray, 0, targetArray, 0, sourceArray.length);

c)

System.arrayCopy(sourceArray, 0, targetArray, 0, sourceArray.length);

d)

System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

67.

What is output of the following code:

public class Test {

   public static void main(String[] args) {

   int[] x = {120, 200, 016};

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

     System.out.print(x[i] + " ");

   }

}

a)

120 200 16

b)

120 200 14

c)

120 200 20

d)

016 is a compile error. It should be written as 16.

68.

Analyze the following code:

public class Test {

   public static void main(String[] args) {

     int[] x = {1, 2, 3, 4};

     int[] y = x;

     x = new int[2];

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

        System.out.print(y[i] + " ");

   }

}

a)

The program displays 1 2 3 4

b)

The program displays 0 0

c)

The program displays 0 0 3 4

d)

The program displays 0 0 0 0

69.

What is the correct term for numbers[99]?

a)

index

b)

index variable

c)

indexed variable

d)

array variable

e)

array

70.

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 30) return?

a)

0

b)

-1

c)

1

d)

2

e)

-2

71.

Suppose a method p has the following heading:

public static int[] p()

What return statement may be used in p()?

a)

return 1;

b)

return {1, 2, 3};

c)

return int[]{1, 2, 3};

d)

return new int[]{1, 2, 3};

72.

The reverse method is defined in the textbook. What is list1 after executing the following statements?

int[] list1 = {1, 2, 3, 4, 5, 6};

list1 = reverse(list1);

a)

list1 is 1 2 3 4 5 6

b)

list1 is 6 5 4 3 2 1

c)

list1 is 0 0 0 0 0 0

d)

list1 is 6 6 6 6 6 6

73.

What is the output of the following code?

int[] myList = {1, 2, 3, 4, 5, 6};

for (int i = myList.length - 2; i >= 0; i--) {

   myList[i + 1] = myList[i];

}

for (int e: myList)

   System.out.print(e + " ");

a)

1 2 3 4 5 6

b)

6 1 2 3 4 5

c)

6 2 3 4 5 1

d)

1 1 2 3 4 5

e)

2 3 4 5 6 1

74.

In the following code, what is the output for list2?

public class Test {

   public static void main(String[] args) {

     int[] list1 = {1, 2, 3};

     int[] list2 = {1, 2, 3};

     list2 = list1;

     list1[0] = 0; list1[1] = 1; list2[2] = 2;

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

        System.out.print(list2[i] + " ");

   }

}

a)

1 2 3

b)

1 1 1

c)

0 1 2

d)

0 1 3

75.

How many elements are in array double[] list = new double[5]?

a)

4

b)

5

c)

6

d)

0

76.

When you return an array from a method, the method returns __________.

a)

a copy of the array

b)

a copy of the first element

c)

the reference of the array

d)

the length of the array

77.

The __________ method sorts the array scores of the double[] type.

a)

java.util.Arrays(scores)

b)

java.util.Arrays.sorts(scores)

c)

java.util.Arrays.sort(scores)

d)

Njava.util.Arrays.sortArray(scores)

78.

When you pass an array to a method, the method receives __________.

a)

a copy of the array

b)

a copy of the first element

c)

the reference of the array

d)

the length of the array

79.

What is the output of the following code?

double[] myList = {1, 5, 5, 5, 5, 1};

double max = myList[0];

int indexOfMax = 0;

for (int i = 1; i < myList.length; i++) {

   if (myList[i] > max) {

     max = myList[i];

      indexOfMax = i;

   }

}

System.out.println(indexOfMax);

a)

0

b)

1

c)

2

d)

3

e)

4

80.

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.

a)

3.4

b)

2.0

c)

3.5

d)

5.5

e)

undefined

81.

Analyze the following code:

public class Test {

   public static void main(String[] args) {

     double[] x = {2.5, 3, 4};

     for (double value: x)

        System.out.print(value + " ");

   }

}

a)

The program displays 2.5, 3, 4

b)

The program displays 2.5 3 4

c)

The program displays 2.5 3.0 4.0

d)

The program displays 2.5, 3.0 4.0

e)

The program has a syntax error because value is undefined.

82.

What is the representation of the third element in an array called a?

a)

a[2]

b)

a(2)

c)

a[3]

d)

a(3)

83.

Analyze the following code:

public class Test {

   public static void main(String[] args) {

     int[] a = new int[4];

     a[1] = 1;

     a = new int[2];

     System.out.println("a[1] is " + a[1]);

   }

}

a)

The program has a compile error because new int[2] is assigned to a.

b)

The program has a runtime error because a[1] is not initialized.

c)

The program displays a[1] is 0.

d)

The program displays a[1] is 1.

84.

Variables that are shared by every instances of a class are __________.

a)

public variables

b)

private variables

c)

instance variables

d)

class variables

85.

__________ represents an entity in the real world that can be distinctly identified.

a)

A class

b)

An object

c)

A method

d)

A data field

86.

Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is _________ in the class.

public static void main(String[] args) {

   xMethod();

}

a)

a static method

b)

an instance method

c)

a static method or an instance method

87.

To declare a constant MAX_LENGTH as a member of the class, you write

a)

final static MAX_LENGTH = 99.98;

b)

final static float MAX_LENGTH = 99.98;

c)

static double MAX_LENGTH = 99.98;

d)

final double MAX_LENGTH = 99.98;

e)

final static double MAX_LENGTH = 99.98;

88.

Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?

a)

x contains an array of ten int values.

b)

x contains an array of ten objects of the Circle type.

c)

x contains a reference to an array and each element in the array can hold a reference to a Circle object.

d)

x contains a reference to an array and each element in the array can hold a Circle object.

89.

Suppose the xMethod() is invoked in the following constructor in a class, xMethod() is _________ in the class.

public MyClass() {

   xMethod();

}

a)

a static method

b)

an instance method

c)

a static method or an instance method

90.

An object is an instance of a __________.

a)

program

b)

class

c)

method

d)

data

91.

The default value for data field of a boolean type, numeric type, object type is ___________, respectively.

a)

true, 1, Null

b)

false, 0, null

c)

true, 0, null

d)

true, 1, null

e)

false, 1, null

92.

To prevent a class from being instantiated, _____________________

a)

don't use any modifiers on the constructor.

b)

use the public modifier on the constructor.

c)

use the private modifier on the constructor.

d)

use the static modifier on the constructor.

93.

You can declare two variables with the same name in __________.

a)

a method one as a formal parameter and the other as a local variable

b)

a block

c)

two nested blocks in a method (two nested blocks means one being inside the other)

d)

different methods in a class

94.

The keyword __________ is required to declare a class.

a)

public

b)

private

c)

class

d)

All of the above.

95.

A method that is associated with an individual object is called __________.

a)

a static method

b)

a class method

c)

an instance method

d)

an object method

96.

________ is invoked to create an object.

a)

A constructor

b)

The main method

c)

A method with a return type

d)

A method with the void return type

97.

Given the declaration Circle x = new Circle(), which of the following statement is most accurate.

a)

x contains an int value.

b)

x contains an object of the Circle type.

c)

x contains a reference to a Circle object.

d)

You can assign an int value to x.

98.

_______ is a construct that defines objects of the same type.

a)

A class

b)

An object

c)

A method

d)

A data field

99.

What modifier should you use on a class so that a class in the same package can access it but a class (including a subclass) in a different package cannot access it?

a)

public

b)

private

c)

protected

d)

Use the default modifier

100.

Polymorphism means ______________.

a)

that data fields should be declared private

b)

that a class can extend another class

c)

that a variable of supertype can refer to a subtype object

d)

that a class can contain another class

101.

Inheritance means ______________.

a)

that data fields should be declared private

b)

that a class can extend another class

c)

that a variable of supertype can refer to a subtype object

d)

that a class can contain another class

102.

Encapsulation means ______________.

a)

that data fields should be declared private

b)

that a class can extend another class

c)

that a variable of supertype can refer to a subtype object

d)

that a class can contain another class

103.

You can create an ArrayList using _________.

a)

new ArrayList[]

b)

new ArrayList[100]

c)

new ArrayList<>()

d)

ArrayList()

104.

What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package?

a)

public

b)

private

c)

protected

d)

Use the default modifier.

105.

Suppose an ArrayList list contains {"red", "green", "red", "green"}. What is the list after the following code?

list.remove("red");

a)

{"red", "green", "red", "green"}

b)

{"green", "red", "green"}

c)

{"green", "green"}

d)

{"red", "green", "green"}

106.

What is the output of the following code:

public class Test {

   public static void main(String[] args) {

     Object o1 = new Object();

     Object o2 = new Object();

     System.out.print((o1 == o2) + " " + (o1.equals(o2)));

   }

}

a)

false false

b)

true true

c)

false true

d)

true false

107.

Invoking _________ removes all elements in an ArrayList x.

a)

x.remove()

b)

x.clean()

c)

x.delete()

d)

x.empty()

e)

x.clear()

108.

Which of the following is incorrect?

a)

A constructor may be static.

b)

A constructor may be private.

c)

A constructor may invoke a static method.

d)

A constructor may invoke an overloaded constructor.

e)

A constructor invokes its superclass no-arg constructor by default if a constructor does not invoke an overloaded constructor or its superclass's constructor.

109.

Assume Cylinder is a subtype of Circle. Analyze the following code:

Cylinder cy = new Cylinder(1, 1);

Circle c = cy;

a)

The code has a compile error.

b)

The code has a runtime error.

c)

The code is fine.

110.

What is the output of running class C?

class A {

   public A() {

     System.out.println(

        "The default constructor of A is invoked");

   }

}

class B extends A {

   public B() {

     System.out.println(

        "The default constructor of B is invoked");

   }

}

public class C {

   public static void main(String[] args) {

     B b = new B();

   }

}

a)

Nothing displayed

b)

"The default constructor of B is invoked"

c)

"The default constructor of A is invoked" followded by "The default constructor of B is invoked"

d)

"The default constructor of B is invoked" followed by "The default constructor of A is invoked"

e)

"The default constructor of A is invoked"

111.

Invoking _________ returns the first element in an ArrayList x.

a)

x.first()

b)

x.get(0)

c)

x.get(1)

d)

x.get()

112.

Which of the following are Java keywords?

a)

instanceOf

b)

instanceof

c)

cast

d)

casting

113.

A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this?

a)

The variable should be marked public.

b)

The variable should be marked private.

c)

The variable should be marked protected.

d)

The variable should have no special access modifier.

e)

The variable should be marked private and an accessor method provided.

114.

Given two reference variables t1 and t2, if t1 == t2 is true, t1.equals(t2) must be ___________.

a)

True

b)

False

115.

What is the output of the following code?

public class Test {

   public static void main(String[] args) {

     new Person().printPerson();

     new Student().printPerson();

   }

}

class Student extends Person {

   private String getInfo() {

     return "Student";

   }

}

class Person {

   private String getInfo() {

   return "Person";

}

   public void printPerson() {

     System.out.println(getInfo());

   }

}

a)

Person Person

b)

Person Student

c)

Stduent Student

d)

Student Person

116.

Object-oriented programming allows you to derive new classes from existing classes. This is called ____________.

a)

encapsulation

b)

inheritance

c)

abstraction

d)

generalization

117.

What is the output of the following code:

public class Test {

   public static void main(String[] args) {

     String s1 = new String("Java");

     String s2 = new String("Java");

     System.out.print((s1 == s2) + " " + (s1.equals(s2)));

   }

}

a)

false false

b)

true true

c)

false true

d)

true false

118.

Given the following code:

class C1 {}

class C2 extends C1 { }

class C3 extends C2 { }

class C4 extends C1 {}

C1 c1 = new C1();

C2 c2 = new C2();

C3 c3 = new C3();

C4 c4 = new C4();

Which of the following expressions evaluates to false?

a)

c1 instanceof C1

b)

c2 instanceof C1

c)

c3 instanceof C1

d)

c4 instanceof C2

119.

To add a node to the the first row and second column in a GridPane pane, use ________.

a)

pane.getChildren().add(node, 1, 2);

b)

pane.add(node, 1, 2);

c)

pane.getChildren().add(node, 0, 1);

d)

pane.add(node, 0, 1);

e)

pane.add(node, 1, 0);

120.

To place a node in the left of a BorderPane p, use ___________.

a)

p.setEast(node);

b)

p.placeLeft(node);

c)

p.setLeft(node);

d)

p.left(node);

121.

To add two nodes node1 and node2 into a pane, use ______.

a)

pane.add(node1, node2);

b)

pane.addAll(node1, node2);

c)

pane.getChildren().add(node1, node2);

d)

pane.getChildren().addAll(node1, node2);

122.

Which of the following statements are true?

a)

A Node can be placed in a Pane.

b)

A Node can be placed in a Scene.

c)

A Pane can be placed in a Control.

d)

A Shape can be placed in a Control.

123.

To remove two nodes node1 and node2 from a pane, use ______.

a)

pane.remove(node1, node2);

b)

pane.removeAll(node1, node2);

c)

pane.getChildren().remove(node1, node2);

d)

pane.getChildren().removeAll(node1, node2);

124.

Analyze the following code:

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.stage.Stage;

import javafx.scene.layout.HBox;

import javafx.scene.shape.Circle;

public class Test extends Application {

   // Override the start method in the Application class

   public void start(Stage primaryStage) {

      HBox pane = new HBox(5);

     Circle circle = new Circle(50, 200, 200);

     pane.getChildren().addAll(circle);

     circle.setCenterX(100);

     circle.setCenterY(100);

     circle.setRadius(50);

     pane.getChildren().addAll(circle);

     // Create a scene and place it in the stage

     Scene scene = new Scene(pane);

      primaryStage.setTitle("Test"); // Set the stage title

      primaryStage.setScene(scene); // Place the scene in the stage

      primaryStage.show(); // Display the stage

   }

   /**

   * The main method is only needed for the IDE with limited

   * JavaFX support. Not needed for running from the command line.

   */

   public static void main(String[] args) {

     launch(args);

   }

}

a)

The program has a compile error since the circle is added to a pane twice.

b)

The program has a runtime error since the circle is added to a pane twice.

c)

The program runs fine and displays one circle.

d)

The program runs fine and displays two circles.

125.

What is the output of the following JavaFX program?

import javafx.application.Application;

import javafx.stage.Stage;

public class Test extends Application {

   public Test() {

     System.out.println("Test constructor is invoked.");

   }

   // Override the start method in the Application class

   public void start(Stage primaryStage) {

     System.out.println("start method is invoked.");

   }

   public static void main(String[] args) {

     System.out.println("launch application.");

     Application.launch(args);

   }

}

a)

launch application. start method is invoked.

b)

start method is invoked. Test constructor is invoked.

c)

Test constructor is invoked. start method is invoked.

d)

launch application. start method is invoked. Test constructor is invoked.

e)

launch application. Test constructor is invoked. start method is invoked.

126.

To place two nodes node1 and node2 in a HBox p, use ___________.

a)

p.add(node1, node2);

b)

p.addAll(node1, node2);

c)

p.getChildren().add(node1, node2);

d)

p.getChildren().addAll(node1, node2);

127.

What is the output of the following code?

import javafx.beans.property.IntegerProperty;

import javafx.beans.property.SimpleIntegerProperty;

public class Test {

   public static void main(String[] args) {

      IntegerProperty d1 = new SimpleIntegerProperty(1);

      IntegerProperty d2 = new SimpleIntegerProperty(2);

     d1.bind(d2);

     System.out.print("d1 is " + d1.getValue()

        + " and d2 is " + d2.getValue());

     d2.setValue(3);

     System.out.println(", d1 is " + d1.getValue()

        + " and d2 is " + d2.getValue());

   }

}

a)

d1 is 2 and d2 is 2, d1 is 3 and d2 is 3

b)

d1 is 2 and d2 is 2, d1 is 2 and d2 is 3

c)

d1 is 1 and d2 is 2, d1 is 1 and d2 is 3

d)

d1 is 1 and d2 is 2, d1 is 3 and d2 is 3

128.

Suppose A is an anonymous inner class in Test. A is compiled into a file named _________.

a)

A.class

b)

Test$A.class

c)

A$Test.class

d)

Test$1.class

e)

Test&1.class

129.

Supose the follwoing program displays a pane in the stage. What is the output if the user presses the DOWN arrow key?

import javafx.application.Application;

import static javafx.application.Application.launch;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;

import javafx.stage.Stage;

// import javafx classes omitted

public class Test1 extends Application {

   public void start(Stage primaryStage) {

     // Code to create and display pane omitted

     Pane pane = new Pane();

     Scene scene = new Scene(pane, 200, 250);

      primaryStage.setTitle("MyJavaFX"); // Set the stage title

      primaryStage.setScene(scene); // Place the scene in the stage

      primaryStage.show(); // Display the stage

     pane.requestFocus();

     pane.setOnKeyPressed(e ->

        System.out.print("Key pressed " + e.getCode() + " "));

     pane.setOnKeyTyped(e ->

     System.out.println("Key typed " + e.getCode()));

   }

/**

* The main method is only needed for the IDE with limited

* JavaFX support. Not needed for running from the command line.

*/

   public static void main(String[] args) {

     launch(args);

   }

}

a)

Key pressed DOWN Key typed UNDEFINED

b)

Key pressed DOWN Key typed

c)

Key typed UNDEFINED

d)

Key pressed DOWN

130.

Fill in the code in the underlined location to display the mouse point location when the mouse is pressed in the pane.

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;

import javafx.stage.Stage;

public class Test extends Application {

   // Override the start method in the Application class

   public void start(Stage primaryStage) {

     Pane pane = new Pane();

     ______________________________________

     Scene scene = new Scene(pane, 200, 250);

     primaryStage.setTitle("Test"); // Set the stage title

      primaryStage.setScene(scene); // Place the scene in the stage

      primaryStage.show(); // Display the stage

   }

   /**

   * The main method is only needed for the IDE with limited JavaFX

   * support. Not needed for running from the command line.

   */

   public static void main(String[] args) {

     launch(args);

   }

}

a)

pane.setOnMouseClicked((e) -> System.out.println(e.getX() + ", " + e.getY()));

b)

pane.setOnMouseReleased(e -> {System.out.println(e.getX() + ", " + e.getY())});

c)

pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY()));

d)

pane.setOnMouseDragged((e) -> System.out.println(e.getX() + ", " + e.getY()));

131.

Analyze the following code.

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.stage.Stage;

public class Test extends Application {

   // Override the start method in the Application class

   public void start(Stage primaryStage) {

     // Create a button and place it in the scene

     Button btOK = new Button("OK");

      btOK.setOnAction(e -> System.out.println("OK 1"));

      btOK.setOnAction(e -> System.out.println("OK 2"));

     Scene scene = new Scene(btOK, 200, 250);

      primaryStage.setTitle("MyJavaFX"); // Set the stage title

      primaryStage.setScene(scene); // Place the scene in the stage

      primaryStage.show(); // Display the stage

   }

   /**

   * The main method is only needed for the IDE with limited JavaFX

   * support. Not needed for running from the command line.

   */

   public static void main(String[] args) {

     launch(args);

   }

}

a)

When clicking the button, the program displays OK1 OK2.

b)

When clicking the button, the program displays OK1.

c)

When clicking the button, the program displays OK2.

d)

The program has a compile error, because the setOnAction method is invoked twice.

132.

To handle the key pressed event on a pane p, register the handler with p using ______.

a)

p.setOnKeyClicked(handler);

b)

p.setOnKeyTyped(handler);

c)

p.setOnKeyReleased(handler);

d)

p.setOnKeyPressed(handler);

133.

Suppose A is an inner class in Test. A is compiled into a file named _________.

a)

A.class

b)

Test$A.class

c)

A$Test.class

d)

Test&A.class

134.

Analyze the following code.

import javafx.application.Application;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.stage.Stage;

public class Test extends Application {

   // Override the start method in the Application class

   public void start(Stage primaryStage) {

     Button btOK = new Button("OK");

      btOK.setOnAction(new EventHandler() {

        public void handle(ActionEvent e) {

          System.out.println("The OK button is clicked");

        }

     });

     Scene scene = new Scene(btOK, 200, 250);

      primaryStage.setTitle("MyJavaFX"); // Set the stage title

      primaryStage.setScene(scene); // Place the scene in the stage

      primaryStage.show(); // Display the stage

   }

   /**

   * The main method is only needed for the IDE with limited JavaFX

   * support. Not needed for running from the command line.

   */

   public static void main(String[] args) {

     launch(args);

   }

}

a)

The program has a compile error because no handlers are registered with btOK.

b)

The program has a runtime error because no handlers are registered with btOK.

c)

The message "The OK button is clicked" is displayed when you click the OK button.

d)

The handle method is not executed when you click the OK button, because no handler is registered with btOK.

135.

To register a source for an action event with a handler, use __________.

a)

source.addAction(handler)

b)

source.setOnAction(handler)

c)

source.addOnAction(handler)

d)

source.setActionHandler(handler)

136.

A JavaFX action event handler contains a method ________.

a)

public void actionPerformed(ActionEvent e)

b)

public void actionPerformed(Event e)

c)

public void handle(ActionEvent e)

d)

public void handle(Event e)

137.

Fill in the code below in the underline:

public class Test {

   public static void main(String[] args) {

     Test test = new Test();

      test.setAction(______________________________);

   }

   public void setAction(T1 t) {

     t.m();

   }

}

interface T1 {

   public void m();

}

a)

() -> System.out.print("Action 1! ")

b)

(e) -> System.out.print("Action 1! ")

c)

System.out.print("Action 1! ")

d)

(e) -> {System.out.print("Action 1! ")}

138.

Which of the following methods is not defined in the Animation class?

a)

pause()

b)

play()

c)

stop()

d)

resume()

139.

Which statement is true about a non-static inner class?

a)

It must implement an interface.

b)

It is accessible from any other class.

c)

It can only be instantiated in the enclosing class.

d)

It must be final if it is declared in a method scope.

e)

It can access private instance variables in the enclosing object.

140.

A JavaFX event handler for event type T is an instance of _______.

a)

ActionEvent

b)

Action

c)

EventHandler

d)

EventHandler<T>

141.

Suppose the following program displays a pane in the stage. What is the output if the user presses the key for letter B?

import javafx.application.Application;

import static javafx.application.Application.launch;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;

import javafx.stage.Stage;

// import javafx classes omitted

public class Test1 extends Application {

   public void start(Stage primaryStage) {

     // Code to create and display pane omitted

     Pane pane = new Pane();

     Scene scene = new Scene(pane, 200, 250);

      primaryStage.setTitle("MyJavaFX"); // Set the stage title

      primaryStage.setScene(scene); // Place the scene in the stage

      primaryStage.show(); // Display the stage

     pane.requestFocus();

     pane.setOnKeyPressed(e ->

     System.out.print("Key pressed " + e.getCode() + " "));

     pane.setOnKeyTyped(e ->

     System.out.println("Key typed " + e.getCode()));

   }

   /**

   * The main method is only needed for the IDE with limited

   * JavaFX support. Not needed for running from the command line.

   */

   public static void main(String[] args) {

     launch(args);

   }

}

a)

Key pressed B Key typed UNDEFINED

b)

Key pressed B Key typed

c)

Key typed UNDEFINED

d)

Key pressed B

142.

A JavaFX action event handler is an instance of _______.

a)

ActionEvent

b)

Action

c)

EventHandler

d)

EventHandler<ActionEvent>

143.

To handle the mouse click event on a pane p, register the handler with p using ______.

a)

p.setOnMouseClicked(handler);

b)

p.setOnMouseDragged(handler);

c)

p.setOnMouseReleased(handler);

d)

p.setOnMousePressed(handler);

144.

Which of the following assignment statements is incorrect?

a)

i = j = k = 1;

b)

i = 1; j = 1; k = 1;

c)

i = 1 = j = 1 = k = 1;

d)

i == j == k == 1;

145.

Suppose x is 1. What is x after x += 2?

a)

0

b)

1

c)

2

d)

3

e)

4

146.

-25 % 5 is _____

a)

1

b)

2

c)

3

d)

4

e)

0

147.

To declare an int variable number with initial value 2, you write

a)

int number = 2L;

b)

int number = 2l;

c)

int number = 2;

d)

int number = 2.0;

148.

What is the exact output of the following code?

double area = 3.5;

System.out.print("area");

System.out.print(area);

a)

3.53.5

b)

3.5 3.5

c)

area3.5

d)

area 3.5

149.

To assign a value 1 to variable x, you write

a)

1 = x;

b)

x = 1;

c)

x := 1;

d)

1 := x;

e)

x == 1;

150.

24 % 5 is _____

a)

1

b)

2

c)

3

d)

4

e)

0

151.

To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159.

a)

variables

b)

methods

c)

constants

d)

classes

152.

According to Java naming convention, which of the following names can be variables?

a)

FindArea

b)

findArea

c)

totalLength

d)

TOTAL_LENGTH

e)

class

153.

____________ is the Java assignment operator.

a)

==

b)

:=

c)

=

d)

=:

154.

To assign a double variable d to a float variable x, you write

a)

x = (long)d

b)

x = (int)d;

c)

x = d;

d)

x = (float)d;

155.

Suppose a Scanner object is created as follows:

Scanner input = new Scanner(System.in);

What method do you use to read a real number?

a)

input.nextDouble();

b)

input.nextdouble();

c)

input.double();

d)

input.Double();

156.

Which of the following expression results in a value 1?

a)

2 % 1

b)

15 % 4

c)

25 % 5

d)

37 % 6

157.

The expression 4 + 20 / (3 - 1) * 2 is evaluated to

a)

4

b)

20

c)

24

d)

9

e)

25

158.

Math.pow(4, 1 / 2) returns __________.

a)

2

b)

2.0

c)

0

d)

1.0

e)

1

159.

To declare a constant MAX_LENGTH inside a method with value 99.98, you write

a)

final MAX_LENGTH = 99.98;

b)

final float MAX_LENGTH = 99.98;

c)

double MAX_LENGTH = 99.98;

d)

final double MAX_LENGTH = 99.98;

160.

Which of the following is a constant, according to Java naming conventions?

a)

MAX_VALUE

b)

Test

c)

read

d)

ReadInt

e)

COUNT

161.

What is x after the following statements?

int x = 2;

int y = 1;

x *= y + 1;

a)

x is 1

b)

x is 2

c)

x is 3

d)

xis 4

162.

What is the value of (double)(5/2)?

a)

2

b)

2.5

c)

3

d)

2.0

e)

3.0

163.

Suppose x is 1. What is x after x -= 1?

a)

0

b)

1

c)

2

d)

-1

e)

-2

164.

Assume x = 4, which of the following is true?

a)

!(x == 4)

b)

x != 4

c)

x == 5

d)

x != 5

165.

Which of the following code displays the area of a circle if the radius is positive.

a)

if (radius != 0) System.out.println(radius radius 3.14159);

b)

if (radius >= 0) System.out.println(radius radius 3.14159);

c)

if (radius >= 0) System.out.println(radius radius 3.14159);

d)

if (radius <= 0) System.out.println(radius radius 3.14159);

166.

The __________ method immediately terminates the program.

a)

System.terminate(0);

b)

System.halt(0);

c)

System.exit(0);

d)

System.quit(0);

e)

System.stop(0);

167.

The equal comparison operator in Java is __________.

a)

<>

b)

!=

c)

==

d)

^=

168.

What is 1 + 1 + 1 + 1 + 1 == 5?

a)

true

b)

false

c)

There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.

169.

Suppose x=10 and y=10. What is x after evaluating the expression (y >= 10) || (x-- > 10).

a)

9

b)

10

c)

11

170.

What is the output of the following code?

int x = 0;

if (x < 4) {

   x = x + 1;

}

System.out.println("x is " + x);

a)

x is 0

b)

x is 1

c)

x is 2

d)

x is 3

e)

x is 4

171.

In Java, the word true is ________.

a)

a Java keyword

b)

a Boolean literal

c)

same as value 1

d)

same as value 0

172.

What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?

a)

true

b)

false

c)

There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.

173.

Analyze the following code.

boolean even = false;

if (even) {

   System.out.println("It is even!");

}

a)

The code displays It is even!

b)

The code displays nothing.

c)

The code is wrong. You should replace if (even) with if (even == true).

d)

The code is wrong. You should replace if (even) with if (even = true).

174.

Which of the following is a possible output from invoking Math.random()?

a)

3.43

b)

0.5

c)

0.0

d)

0.0

175.

Assume x = 4 and y = 5, which of the following is true?

a)

x < 5 && y < 5

b)

x < 5 || y < 5

c)

x > 5 && y > 5

d)

x > 5 || y > 5

176.

Which of the following are so called short-circuit operators?

a)

+=

b)

&

c)

||

d)

|

177.

Analyze the following code:

boolean even = false;

if (even = true) {

   System.out.println("It is even");

}

a)

The program has a compile error.

b)

The program has a runtime error.

c)

The program runs fine, but displays nothing.

d)

The program runs fine and displays It is even.

178.

The "less than or equal to" comparison operator in Java is __________.

a)

<

b)

<=

c)

=<

d)

<<

e)

!=

179.

Suppose x is a char variable with a value 'b'. What is the output of the statement System.out.println(++x)?

a)

a

b)

b

c)

c

d)

d

180.

The Unicode of 'a' is 97. What is the Unicode for 'c'?

a)

96

b)

97

c)

98

d)

99

181.

The statement System.out.printf("%3.1f", 1234.56) outputs ___________.

a)

123.4

b)

123.5

c)

1234.5

d)

1234.56

e)

1234.6

182.

Which of the following statement prints smith\exam1\test.txt?

a)

System.out.println("smith\exam1\test.txt");

b)

System.out.println("smith\\exam1\\test.txt");

c)

System.out.println("smith\"exam1\"test.txt");

d)

System.out.println("smith"\exam1"\test.txt");

183.

Which of the following is the correct expression of character 4?

a)

4

b)

"4"

c)

'\0004'

d)

'4'

184.

Suppose s1 and s2 are two strings. What is the result of the following code?

s1.equals(s2) == s2.equals(s1)

a)

True

b)

False

185.

What is Math.ceil(3.6)?

a)

3.0

b)

3

c)

4.0

d)

5.0

186.

What is Math.round(3.6)?

a)

3.0

b)

3

c)

4

d)

4.0

187.

Which of the following assignment statements is correct?

a)

char c = 'd';

b)

char c = '100';

c)

char c = "d";

d)

char c = "100";

188.

What is the output of System.out.println('z' - 'a')?

a)

25

b)

26

c)

a

d)

z

189.

What is Math.rint(3.5)?

a)

3.0

b)

3

c)

4

d)

4.0

e)

5.0

190.

Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?

a)

System.out.println(i);

b)

System.out.println((char)i);

c)

System.out.println((int)i);

d)

System.out.println(i + " ");

191.

What is the return value of "SELECT".substring(0, 5)?

a)

"SELECT"

b)

"SELEC"

c)

"SELE"

d)

"ELECT"

192.

A Java character is stored in __________.

a)

one byte

b)

two bytes

c)

three bytes

d)

four bytes

193.

The statement System.out.printf("%5d", 123456) outputs ___________.

a)

12345

b)

23456

c)

123456

d)

12345.6

194.

"abc".compareTo("aba") returns ___________.

a)

1

b)

2

c)

-1

d)

-2

e)

0

195.

What is Math.floor(3.6)?

a)

3.0

b)

3

c)

4

d)

5.0

196.

What is the return value of "SELECT".substring(4, 4)?

a)

an empty string

b)

C

c)

T

d)

E

197.

The expression "Java " + 1 + 2 + 3 evaluates to ________.

a)

Java123

b)

Java6

c)

Java 123

d)

java 123

e)

Illegal expression

198.

An int variable can hold __________.

a)

120L

b)

120

c)

120.0

d)

"x"

e)

"120"

199.

The statement System.out.printf("%10s", 123456) outputs ___________. (Note: * represents a space)

a)

123456****

b)

23456*****

c)

12345*****

d)

****123456

200.

To check whether a char variable ch is an uppercase letter, you write ___________.

a)

(ch >= 'A' && ch >= 'Z')

b)

(ch >= 'A' && ch <= 'Z')

c)

(ch >= 'A' || ch <= 'Z')

d)

('A' <= ch <= 'Z')

201.

Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.

a)

66

b)

B

c)

A1

d)

illegal expression

202.

Which of the following is the correct statement to return JAVA?

a)

toUpperCase("Java")

b)

"Java".toUpperCase("Java")

c)

"Java".toUpperCase()

d)

String.toUpperCase("Java")

203.

Will System.out.println((char)4) display 4?

a)

YES

b)

NO