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
Which of the following best describes the behavior of the code segment?
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 Wayground
10 questions
Indexing and Slicing in Python

Quiz
•
4th Grade - University
10 questions
2025 python class first quiz

Quiz
•
9th Grade - University
10 questions
Database Fundamentals

Quiz
•
KG - University
10 questions
Advanced Java Study Guide

Quiz
•
11th - 12th Grade
12 questions
CodeHS Unit 1

Quiz
•
9th - 12th Grade
10 questions
Python: Functions and Parameters

Quiz
•
9th - 12th Grade
10 questions
Introduction to Arrays

Quiz
•
KG - University
10 questions
Session 1

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
18 questions
Writing Launch Day 1

Lesson
•
3rd Grade
11 questions
Hallway & Bathroom Expectations

Quiz
•
6th - 8th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
Discover more resources for Computers
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
62 questions
Spanish Speaking Countries, Capitals, and Locations

Quiz
•
9th - 12th Grade
20 questions
First Day of School

Quiz
•
6th - 12th Grade
6 questions
Maier - AMDM - Unit 1 - Quiz 1 - Estimation

Quiz
•
12th Grade
21 questions
Arithmetic Sequences

Quiz
•
9th - 12th Grade
21 questions
9th Grade English Diagnostic Quiz

Quiz
•
9th - 12th Grade
7 questions
Characteristics of Life

Interactive video
•
11th Grade - University