Advanced Java Study Guide

Advanced Java Study Guide

11th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

LA5.C5: Branching and Subroutines

LA5.C5: Branching and Subroutines

9th Grade - University

14 Qs

SENATIC Parcial Guía 3_PseInt

SENATIC Parcial Guía 3_PseInt

10th Grade - University

15 Qs

INTRODUCCION A LA PROGRAMACION

INTRODUCCION A LA PROGRAMACION

6th Grade - University

10 Qs

2025 python class first quiz

2025 python class first quiz

9th Grade - University

10 Qs

UNKNOWN TRICKS AND TIME SAVERS

UNKNOWN TRICKS AND TIME SAVERS

11th Grade

10 Qs

DNS dan Web server

DNS dan Web server

11th Grade

10 Qs

Python List

Python List

4th Grade - University

15 Qs

Advanced Java Study Guide

Advanced Java Study Guide

Assessment

Quiz

Computers

11th - 12th Grade

Hard

Created by

Joshua Donato

Used 8K+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

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?

int

int[]

int[][]

int[][][]

Answer explanation

A three-dimensional array in Java is actually an array of two-dimensional arrays. Therefore, the outermost for-each loop must iterate through these two-dimensional arrays which are of type int[][].

2.

FILL IN THE BLANK QUESTION

1 min • 1 pt

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

Answer explanation

In Java, the instanceof keyword is used to test if an object is of a given type. It is also known as type comparison operator because it compares the instance of an Object with a type.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

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?

((King)cp).getChecked()

(King)(cp).getChecked()

(King)cp.getChecked()

((King)cp.getChecked())

Answer explanation

The ChessPiece cp must be typecast to King in order to access methods unique to King. In Java, the syntax for this is ((King)cp).getChecked().

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

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]?

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

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

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

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

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

Answer explanation

To do a for loop in two variables, use comma-separated variable declarations, combine terminating conditions with the && operator, and comma-separate the incrementing commands. In this case, the syntax is

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

5.

FILL IN THE BLANK QUESTION

1 min • 1 pt

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

Answer explanation

An arbitrary number of elements of a Collection such as an ArrayList can be added to another ArrayList using the addAll() function.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

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?

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++)

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++)

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++)

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++)

Answer explanation

To prevent the throwing of an ArrayIndexOutOfBoundsException, the outer loop should iterate starting at either 0 or x-1, whichever is greater. Likewise, it should stop iterating at either 7 or x+1, whichever is smaller. The inner loop should be bounded similarly but with y. Because we want the entire 3x3 region and not just the diagonal, we should use two nested for loops. With all of that in mind, the correct code is:

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++)

7.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

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

Select all that apply.

Identical code in different for loops.

Identical code in different classes.

An important part of an existing function.

Code within nested if statements that have no else statements.

Answer explanation

Repeated code such as identical code in different for loops or identical code in different classes with only small differences should be moved to its own function. Code which is an important part of an existing function is already in its own function and doesn't need to be moved. Nested if statements with no else staements can be simplified to a single if statement using the && operator, but doesn't need to go in its own function.

Create a free account and access millions of resources

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

By signing up, you agree to our Terms of Service & Privacy Policy

Already have an account?