
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
Technical Terms - Internet (A-Z) - Avatar
Quiz
•
12th Grade
10 questions
Technical Terms - Internet (A-Z) - W3C
Quiz
•
12th Grade
10 questions
Technical Terms - Internet (A-Z) - SMTP
Quiz
•
12th Grade
10 questions
Intro to Windows Server 2012
Quiz
•
12th Grade
10 questions
Câu hỏi về thiết bị máy tính
Quiz
•
7th Grade - University
10 questions
Microsoft Word 3ºB
Quiz
•
12th Grade
10 questions
HT3.2- Validation and Reliability
Quiz
•
8th Grade - University
11 questions
65. Logic - Logic Gates and Circuits Quiz
Quiz
•
9th - 12th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
10 questions
Probability Practice
Quiz
•
4th Grade
15 questions
Probability on Number LIne
Quiz
•
4th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
6 questions
Appropriate Chromebook Usage
Lesson
•
7th Grade
10 questions
Greek Bases tele and phon
Quiz
•
6th - 8th Grade