Which of the following best describes the behavior of the code segment?
Topics 7 & 8 - Static Methods/Variables and Null Keyword

Quiz
•
Computers
•
12th Grade
•
Hard
SAMUEL KEENER
Used 4+ times
FREE Resource
8 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Exactly 5 Element objects are created.
Exactly 10 Element objects are created.
Between 0 and 5 Element objects are created, and Element.max_value is increased only for the first object created.
Between 1 and 5 Element objects are created, and Element.max_value is increased for every object created.
Between 1 and 5 Element objects are created, and Element.max_value is increased for at least one object created.
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following class definition.
public class WordClass
{
private final String word;
private static String max_word = "";
public WordClass (String s)
{
word = s;
if (word.length() > max_word.length())
{
max_word = word;
}
}
}
Which of the following is a true statement about the behavior of WordClass objects?
A WordClass object can change the value of the variable word more than once.
Every time a WordClass object is created, the max_word variable is referenced.
Every time a WordClass object is created, the value of the max_word variable changes.
No two WordClass objects can have their word length equal to the length of max_word.
The value of the max_word variable cannot be changed once it has been initialized.
3.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following class definition.
public class Something
{
private static int count = 0;
public Something()
{
count += 5;
}
public static void increment()
{
count++;
}
}
The following code segment appears in a method in a class other than Something.
Something s = new Something();
Something.increment();
Which of the following best describes the behavior of the code segment?
The code segment does not compile because the increment method should be called on an object of the class Something, not on the class itself.
The code segment creates a Something object s. The class Something’s static variable count is initially 0, then increased by 1.
The code segment creates a Something object s. The class Something’s static variable count is initially 0, then increased by 5, then increased by 1.
The code segment creates a Something object s. After executing the code segment, the object s has a count value of 1.
The code segment creates a Something object s. After executing the code segment, the object s has a count value of 5.
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Which of these should not be declared as static?
A Frog class variable that counts the number of Frog objects that have been made.
A Frog class variable that counts the number of hops a Frog object has performed.
A Frog class variable that counts the number of hops that all Frog objects have performed in total.
A Frog class variable that counts the maximum number of total hops that any individual Frog object has performed.
5.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
A Temperature class is created that stores a double to represent a recorded temperature and another double to represent the max temperature recorded for all Temperature objects.
Identify which of the following variables and methods could be declared as static.
Variable: temperature
Variable: maxTemperature
Constructor: Temperature(double t)
Method: getTemperature()
Method: getMaxTemperature()
Method: fahrenheitToCelsius(double f)
temperature and getTemperature
maxTemperature and getMaxTemperature
maxTemperature, getMaxTemperature, and fahrenheitToCelsius
fahrenheitToCelsius
temperature, getTemperature, and fahreheitToCelsius
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
The following code segment appears in a class other than Backyard. It is intended to print true if b1 and b2 have the same lengths and widths, and to print false otherwise. Assume that x, y, j, and k are properly declared and initialized variables of type int.
Backyard b1 = new Backyard(x, y);
Backyard b2 = new Backyard(j, k);
System.out.println( /* missing code */ );
Which of the following can be used as a replacement for /* missing code */ so the code segment works as intended?
Responses
b1 == b2
b1.equals(b2)
equals(b1, b2)
b1.equals(b2.getLength(), b2.getWidth())
b1.length == b2.length && b1.width == b2.width
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following can replace /* missing condition */ so that the printDetails method CANNOT cause a run-time error?
I. !borrower.equals(null)
II. borrower != null
III. borrower.getName() != null
I only
II only
III only
I and II
II and III
8.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
cutFirst is intended to cut off the first letter of each element in an array of Strings, that may contain empty indexes. Which of these would fill in missing condition to ensure that no StringIndexOutOfBounds or NullPointer exceptions are thrown?
str[i] == null || str[i].length() > 0
str[i] != null || str[i].length() > 0
str[i] != null && str[i].length() > 0
str[i] == null || str[i].length() == 0
Similar Resources on Quizizz
10 questions
Python Basics Quiz

Quiz
•
9th - 12th Grade
12 questions
Java Class vocabulary

Quiz
•
9th Grade - University
10 questions
Session 1

Quiz
•
9th - 12th Grade
10 questions
Indexing and Slicing in Python

Quiz
•
4th Grade - University
6 questions
Procedures Practice Part 2

Quiz
•
9th - 12th Grade
13 questions
NOCTI Computer Programming

Quiz
•
12th Grade
10 questions
APCSP 3.7 Debugging

Quiz
•
9th - 12th Grade
13 questions
Control Structures in Python

Quiz
•
11th - 12th Grade
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade
Discover more resources for Computers
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
20 questions
Taxes

Quiz
•
9th - 12th Grade
17 questions
Parts of Speech

Quiz
•
7th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression

Quiz
•
9th - 12th Grade
20 questions
Inequalities Graphing

Quiz
•
9th - 12th Grade
10 questions
Identifying equations

Quiz
•
KG - University