wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Advanced Java Study Guide

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

Consider a three-dimensional array

int[][][] numbers = new int[10][10][10].

If this array were to be looped through using for-each loops, what type of variable must be declared in the outermost loop?

a)

int

b)

int[]

c)

int[][]

d)

int[][][]

2.

What keyword in Java is used to determine if an Object is a certain class?

(a)  

3.

Consider two classes class ChessPiece and class King extends ChessPiece. Suppose King has a method getChecked() that is not found in the super class.


Which of the following can be used with ChessPiece cp to access the getChecked() method?

a)

((King)cp).getChecked()

b)

(King)(cp).getChecked()

c)

(King)cp.getChecked()

d)

((King)cp.getChecked())

4.

Consider a two-dimensional array

int[][] grid = new int[8][8]. Which of these for loops will iterate only through the elements on the diagonal from grid[5][3] to grid[7][1]?

a)

for(int i = 5, j = 3; i <= 7 && j >= 1; i++, j--)

b)

for(int i = 5; i<= 7; i++)

for(int j = 3; j >= 1; j--)

c)

for(int i = 5, j = 3; i <= 7 || j >= 1; i++, j--)

d)

for(int i = 5 && j = 3; i <= 7 && j >= 1; i++ && j--)

5.

What function is used to add the contents of an ArrayList to another ArrayList?

(a)  

6.

Consider an array

int[][] grid = new int[8][8]. Given two arbitary indices x and y, which of the following for loops will iterate through the 3x3 region centered on (x,y) without ever throwing an ArrayIndexOutOfBoundsException?

a)

for(int i = Math.max(0,x-1); i <= Math.min(7,x+1); i++)

for(int j = Math.max(0,y-1); j <= Math.min(7,y+1); j++)

b)

for(int i = Math.max(0,x-1), j = Math.max(0,y-1); i <= Math.min(7,x+1) && j <= Math.min(7,y+1); i++, j++)

c)

for(int i = Math.min(0,x-1); i <= Math.max(7,x+1); i++)

for(int j = Math.min(0,y-1); j <= Math.max(7,y+1); j++)

d)

for(int i = Math.min(0,x-1), j = Math.min(0,y-1); i <= Math.max(7,x+1) && j <= Math.max(7,y+1); i++, j++)

7.

Which of the following is best refactored by moving it to a separate function?

Select all that apply.

a)

Identical code in different for loops.

b)

Identical code in different classes.

c)

An important part of an existing function.

d)

Code within nested if statements that have no else statements.

8.

Consider two classes class ChessPiece and class Knight extends ChessPiece. Suppose ChessPiece and Knight have the same method getMoveset().


If Knight k = new Knight(), which of the following is executed when calling k.getMoveset()?

a)

Knight.getMoveset(), then ChessPiece.getMoveset()

b)

ChessPiece.getMoveset(), then Knight.getMoveset()

c)

Knight.getMoveset()

d)

ChessPiece.getMoveset()

9.

Consider two classes class ChessPiece and class Rook extends ChessPiece. Which of the following are valid declarations? Select all that apply.

a)

ChessPiece cp = new ChessPiece();

b)

ChessPiece cp = new Rook();

c)

Rook r = new ChessPiece();

d)

Rook r = new Rook();

10.

Which of the following interfaces is used to implement mouse click functionality?

a)

MouseAdapter

b)

MouseListener

c)

MouseMotionListener

d)

MouseWheelListener