
Topics 7 & 8 - Static Methods/Variables and Null Keyword
Authored by SAMUEL KEENER
Computers
12th Grade
Used 8+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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
Access all questions and much more by creating a free account
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
Already have an account?
Similar Resources on Wayground
10 questions
Office
Quiz
•
1st - 12th Grade
10 questions
ICT as Platform for Change
Quiz
•
11th - 12th Grade
10 questions
emtech
Quiz
•
12th Grade
10 questions
Visual Basic 2010
Quiz
•
8th Grade - University
12 questions
1.2.4. Types of Programming Language
Quiz
•
12th Grade
11 questions
Types of Mass Media
Quiz
•
10th Grade - Professi...
11 questions
Test evaluation word SP3S1
Quiz
•
12th Grade
13 questions
Prueba Diagnostica de Tecnología
Quiz
•
6th Grade - University
Popular Resources on Wayground
8 questions
Spartan Way - Classroom Responsible
Quiz
•
9th - 12th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
14 questions
Boundaries & Healthy Relationships
Lesson
•
6th - 8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
3 questions
Integrity and Your Health
Lesson
•
6th - 8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
9 questions
FOREST Perception
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade