Advanced Java Study Guide

Quiz
•
Computers
•
11th - 12th Grade
•
Hard
Joshua Donato
Used 8K+ times
FREE Resource
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
Similar Resources on Wayground
12 questions
C++ References

Quiz
•
6th - 12th Grade
15 questions
Python бағдарламалау тілі

Quiz
•
11th Grade
15 questions
JavaScript and Graphics

Quiz
•
9th - 12th Grade
10 questions
Recursion in Java (AP Computer Science A)

Quiz
•
9th - 12th Grade
10 questions
Java Data Types

Quiz
•
11th Grade
11 questions
CodeHS 5.3 Using Arrays

Quiz
•
9th - 12th Grade
10 questions
Objects & Classes

Quiz
•
11th - 12th Grade
15 questions
Intro to Java Loops

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade