Advanced Java Study Guide
Quiz
•
Computers
•
11th - 12th Grade
•
Hard
Joshua Donato
Used 8K+ times
FREE Resource
Enhance your content in a minute
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

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
10 questions
SDD HSC Quiz 5A Q1-10
Quiz
•
12th Grade
10 questions
Programação Front End - HTML 5 e CSS
Quiz
•
11th Grade
10 questions
Pseudocode WHILE Loops
Quiz
•
10th - 12th Grade
10 questions
TỪ BÀI TOÁN ĐẾN CHƯƠNG TRÌNH
Quiz
•
11th Grade
10 questions
Advanced SQL
Quiz
•
KG - University
15 questions
EXAMEN EXCEL
Quiz
•
11th Grade
10 questions
Python - PyGame - 1
Quiz
•
11th - 12th Grade
15 questions
Subprograme. Proceduri
Quiz
•
11th Grade
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
6 questions
FOREST Self-Discipline
Lesson
•
1st - 5th Grade
7 questions
Veteran's Day
Interactive video
•
3rd Grade
20 questions
Weekly Prefix check #2
Quiz
•
4th - 7th Grade
Discover more resources for Computers
8 questions
Veterans Day Quiz
Quiz
•
12th Grade
28 questions
Ser vs estar
Quiz
•
9th - 12th Grade
19 questions
Explore Triangle Congruence and Proofs
Quiz
•
9th - 12th Grade
20 questions
-AR -ER -IR present tense
Quiz
•
10th - 12th Grade
10 questions
DNA Replication Concepts and Mechanisms
Interactive video
•
7th - 12th Grade
20 questions
Food Chains and Food Webs
Quiz
•
7th - 12th Grade
15 questions
Identify Triangle Congruence Criteria
Quiz
•
9th - 12th Grade
23 questions
Similar Figures
Quiz
•
9th - 12th Grade
