Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Final Review

Total questions: 50

Worksheet time: 49mins

Name
Class
Date
1.

Which command is written incorrectly?

a)

putBall();

b)

putball();

c)

turnLeft();

d)

takeBall();

2.

What is a code comment?

a)

A way to teach Karel a new word

b)

A way to give notes to the reader to explain what your code is doing

c)

A message to your teacher in code

d)

A place to write whatever you want in your code

3.
Why does a programmer indent their code?
a)
Helps show the structure of the code.
b)
Easier for other people to understand.
c)
A key part of good programming style!
d)
All of the above
4.
Which type of data is used to enter the value ("Welcome")?
a)
Text
b)
Characters
c)
String
d)
Boolean
5.
Which type of data is used to enter the value (True)?
a)
Float
b)
Boolean
c)
Check box
d)
ٍString
6.

We use For loop ..........

a)
To repeat a specified number of operations.
b)
To repeat a unspecified number of operations.
c)
All answers are correct
7.

We use While loop ..........

a)
To repeat a specified number of operations.
b)
To repeat a unspecified number of operations.
c)
All answers are correct
8.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
9.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

10.

In Java, which keyword is used to refer to the parent class of a class?

a)

parent

b)

super

c)

this

d)

base

11.

What keyword is used to inherit a class in Java?

a)

extends

b)

implements

c)

inherits

d)

uses

12.

If a class has multiple methods having the same name but different in parameters, it is known as ____ overloading.

a)

class

b)

object

c)

method

d)

data

13.
In the statement 
 Bank tom = new Bank(5000.0);
Which is the class?
a)
Bank
b)
tom
c)
new
d)
5000.0
14.
How many objects can be made from a class?  
a)
None, you make classes from objects
b)
one
c)
As many as you want
d)
All of the above
15.

To create an object in java we use the keyword new.

a)

True

b)

False

16.

TextBook english = new Textbook();

In the above snippet, TextBook is a _______.

a)

Object

b)

Data member

c)

Member function

d)

Class

17.

A template for an object.

a)

class

b)

object

c)

method

d)

field

18.

Which keyword is used to refer to the current object in a Java class?

a)

this

b)

current

c)

super

d)

self

19.

What is a method?

a)

A. A procedure that is defined by the user.

b)

B. A keyword used to loop for a fixed amount of time.

c)

C. A place where we can store data.

d)

D. The type that is given to a variable.

20.

What is a return value?

a)

A. The value that a method prints to the screen.

b)

B. The value that is inputted to a method.

c)

C. The value that a user inputs to a program.

d)

D. The value that a method outputs.

21.

Why do we use methods in Java?

a)

To make code easier to understand

b)

To avoid repeated code

c)

To simplify code

d)

All of the above

22.

What kind of error is a syntax error, where the code isn't written in proper Java?

a)

compile-time error

b)

runtime error

c)

exception

d)

SyntaxErrorException

23.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

24.

In the following code, what is the name of the method?


public void squared(int num1)

a)

public

b)

void

c)

squared

d)

num1

25.
Based on the statement below, which of the following statements gives the length of the data array?
double[ ] data = new double[10];
a)
data.size()
b)
data.length
c)
data.size
d)
data.length()
26.
The ArrayList class ____ method returns the current ArrayList size.
a)
size
b)
capacity
c)
length
d)
rows
27.
What does the following segment of code print out? int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println(numArray.length);
a)
4
b)
5
c)
6
d)
7
28.
What is the correct way to initialize an array with 10 positions?
a)
int numbers = new int[10];
b)
int[] numbers = new int[];
c)
int[10] numbers = new int[10];
d)
int[] numbers = new int[10];
29.
What value is at index 3 in this array?  String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
a)
Mack
b)
Dennis
c)
Dee
d)
Charlie
30.

Which of the following is true about the size of Arrays and ArrayLists in Java?

a)

Arrays have a fixed size, while ArrayLists can dynamically grow.

b)

Both Arrays and ArrayLists have a fixed size.

c)

Both Arrays and ArrayLists can dynamically grow.

d)

Arrays can dynamically grow, while ArrayLists have a fixed size.

31.

How can we teach Karel new commands?

a)

A. A for loop

b)

B. A while loop

c)

C. Define a new method

d)

D. The run method

32.

Say you want to write a program to have Karel to pick up all of the tennis balls in a location, but you don’t know how many tennis balls there are. Which control structure would you use?

a)

An if statement

b)

A for loop

c)

A while loop

d)

An if/else statement

33.

What data type would you use to store names of students?

a)

String

b)

char

c)

boolean

d)

None of these

34.

How would you declare a variable storing a person's name?

a)

string name = "Jeff";

b)

name String = "Jeff";

c)

String name = Jeff;

d)

String name = "Jeff";

35.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

36.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

37.

Assume that x, y, and z have been declared as follows:


boolean x = true;

boolean y = false;

boolean z = true;


Which of the following expressions evaluates to true?

a)

x && y && z

b)

x && y || z && y

c)

!(x && y) || z

d)

!(x || y) && z

e)

x && y || !z

38.

What does a multi-line comment look like in Java?

a)

/* Comment */

b)

? Comment ?

c)

Comment **

d)

-Java Comment-

39.

What does a single-line comment look like in Java?

a)

//comment

b)

\\comment

c)

/*comment*/

d)

/comment

40.

The following code segment will print (a)  

System.out.println(6 % 9);

41.
A variable that holds a character
a)
String
b)
boolean
c)
int
d)
char
42.
What is at the end of a line of code?
a)
#
b)
;
c)
)
d)
>
43.

What is the result of the expression 12−4/2.012-4/2.0 in Java?

a)

4

b)

4.0

c)

10

d)

10.0

44.

What is the result of the expression 5+15/3∗2−8%35 + 15 / 3 * 2 - 8 \% 3 in Java?

a)

13

b)

10

c)

11

d)

14

45.
The purpose of a(n) _________ is to initialize the instance variables of a newly instantiated object.
a)
Constructor
b)
Class
c)
Formal Parameter
d)
Object
46.
An object has  __________ as defined by the methods of its class.
a)
Scope
b)
Identity
c)
Behavior
d)
State
47.

Can be accessed only by other members of their own class

a)

Public

b)

Private

c)

Closed

d)

Method

48.

Can be accessed by other members outside their own class

a)

Private

b)

Public

c)

Source Code

d)

OOP

49.

The (a)   keyword is used to create methods that do not return a value in Java.

50.

A(n) (a)   method returns a value.