wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OCA Unit 1

Total questions: 23

Worksheet time: 17mins

Name
Class
Date
1.

Which of the following are valid Java identifiers? (Choose all that apply)

a)

A$B

b)

_helloWorld

c)

1980_s

d)

java.lang

e)

Public

2.

What is the output of the following program?

a)

Line 6 generates a compiler error.

b)

Line 7 generates a compiler error.

c)

Empty = false, Brand =

d)

Empty = false, Brand = null

e)

Empty = null, Brand = null

3.

Which of the following are true? (Choose all that apply)

a)

Line 5 generates a compiler error.

b)

Line 7 generates a compiler error.

c)

Line 8 generates a compiler error.

d)

Line 6 generates a compiler error.

e)

The code compiles as is.

4.

Given the following class, which of the following is true? (Choose all that apply)

a)

If String result = "done"; is inserted on line 2, the code will compile.

b)

If String result = "done"; is inserted on line 4, the code will compile.

c)

If String result = "done"; is inserted on line 6, the code will compile.

d)

If String result = "done"; is inserted on line 9, the code will compile.

e)

None of the above changes will make the code compile.

5.

Given the following classes, which of the following can independently replace INSERT

IMPORTS HERE to make the code compile? (Choose all that apply)

a)

import aquarium.*;

b)

import aquarium.*.Jelly;

c)

import aquarium.jellies.Jelly;

d)

import aquarium.jellies.*;

e)

import aquarium.jellies.Jelly.*;

6.

Given the following classes, what is the maximum number of imports that can be removed

and have the code still compile?

a)

0

b)

1

c)

2

d)

3

e)

4

7.

Given the following classes, which of the following snippets can be inserted in place of

INSERT IMPORTS HERE and have the code compile? (Choose all that apply)

a)

import aquarium.*;

b)

import aquarium.Water;

import aquarium.jellies.*;

c)

import aquarium.*;

import aquarium.jellies.Water;

d)

import aquarium.*;

import aquarium.jellies.*;

e)

import aquarium.Water;

import aquarium.jellies.Water;

8.

Given the following class, which of the following calls print out Blue Jay? (Choose all that

apply)

a)

java BirdDisplay Sparrow Blue Jay

b)

java BirdDisplay Sparrow "Blue Jay"

c)

java BirdDisplay Blue Jay Sparrow

d)

java BirdDisplay "Blue Jay" Sparrow

e)

java BirdDisplay.class Sparrow "Blue Jay"

9.

Which of the following legally fill in the blank so you can run the main() method from the

command line? (Choose all that apply)

a)

String[] _names

b)

String[] 123

c)

String abc[]

d)

String _Names[]

e)

String... $n

10.

Which of the following are legal entry point methods that can be run from the command

line? (Choose all that apply)

a)

private static void main(String[] args)

b)

public static final main(String[] args)

c)

public void main(String[] args)

d)

public static void test(String[] args)

e)

public static void main(String[] args)

11.

Which of the following are true? (Choose all that apply)

a)

An instance variable of type double defaults to null.

b)

An instance variable of type int defaults to null.

c)

An instance variable of type String defaults to null.

d)

An instance variable of type double defaults to 0.0.

e)

An instance variable of type int defaults to 0.0.

12.

Which of the following are true? (Choose all that apply)

a)

None of these

b)

A local variable of type boolean defaults to null.

c)

A local variable of type float defaults to 0.

d)

A local variable of type boolean defaults to false.

e)

A local variable of type float defaults to 0.0.

13.

Which of the following are true? (Choose all that apply)

a)

An instance variable of type boolean defaults to false.

b)

An instance variable of type boolean defaults to true.

c)

An instance variable of type boolean defaults to null.

d)

An instance variable of type int defaults to 0.

e)

An instance variable of type int defaults to 0.0.

14.

Given the following class in the file /my/directory/named/A/Bird.java:

INSERT CODE HERE

public class Bird { }

Which of the following replaces INSERT CODE HERE if we compile from /my/directory?

(Choose all that apply)

a)

package my.directory.named.a;

b)

package my.directory.named.A;

c)

package named.a;

d)

package named.A;

e)

package a;

15.

Which of the following lines of code compile? (Choose all that apply)

a)

int i1 = 1_234;

b)

double d1 = 1_234_.0;

c)

double d2 = 1_234._0;

d)

double d3 = 1_234.0_;

e)

double d4 = 1_234.0;

16.

Given the following class, which of the following lines of code can replace INSERT CODE

HERE to make the code compile? (Choose all that apply)

a)

int amount = 9L;

b)

int amount = 0b101;

c)

int amount = 0xE;

d)

double amount = 0xE;

e)

double amount = 1_2_.0_0;

17.

Which of the following are true? (Choose all that apply)

a)

Bunny is a class.

b)

bun is a class.

c)

main is a class.

d)

Bunny is a reference to an object.

e)

bun is a reference to an object.

18.

Which represent the order in which the following statements can be assembled into a pro-

gram that will compile successfully? (Choose all that apply)

a)

A, B, C

b)

B, C, A

c)

C, B, A

d)

B, A

e)

C, A

19.

Suppose we have a class named Rabbit. Which of the following statements are true?

(Choose all that apply)

a)

The Rabbit object from line 3 is first eligible for garbage collection immediately

following line 6.

b)

The Rabbit object from line 3 is first eligible for garbage collection immediately

following line 8.

c)

The Rabbit object from line 3 is first eligible for garbage collection immediately

following line 12.

d)

The Rabbit object from line 4 is first eligible for garbage collection immediately

following line 9.

e)

The Rabbit object from line 4 is first eligible for garbage collection immediately

following line 11.

20.

What is true about the following code? (Choose all that apply)

a)

finalize() is guaranteed to be called.

b)

finalize() might or might not be called

c)

finalize() is guaranteed not to be called.

d)

Garbage collection is guaranteed to run.

e)

Garbage collection might or might not run.

21.

What does the following code output?

a)

0

b)

4

c)

Compilation fails on line 3.

d)

Compilation fails on line 4.

e)

Compilation fails on line 7.

22.

Which of the following are true statements? (Choose all that apply)

a)

Java allows operator overloading.

b)

Java code compiled on Windows can run on Linux.

c)

Java has pointers to specific locations in memory.

d)

Java is a procedural language.

e)

Java is an object-oriented language.

23.

Which of the following are true? (Choose all that apply)

a)

javac compiles a .class file into a .java file.

b)

javac compiles a .java file into a .bytecode file.

c)

javac compiles a .java file into a .class file.

d)

Java takes the name of the class as a parameter.

e)

Java takes the name of the .bytecode file as a parameter.