Topics 7 & 8 - Static Methods/Variables and Null Keyword

Topics 7 & 8 - Static Methods/Variables and Null Keyword

12th Grade

8 Qs

quiz-placeholder

Similar activities

Scratch Programming

Scratch Programming

1st - 12th Grade

13 Qs

Quiz: Python Conditional Statements

Quiz: Python Conditional Statements

12th Grade

10 Qs

Hour of Code

Hour of Code

6th - 12th Grade

12 Qs

Python Basics

Python Basics

6th Grade - University

10 Qs

Brawl stars facts and stuff

Brawl stars facts and stuff

KG - Professional Development

10 Qs

Indexing and Slicing in Python

Indexing and Slicing in Python

4th Grade - University

10 Qs

AP CSP Procedures

AP CSP Procedures

12th Grade

6 Qs

Java while loops

Java while loops

10th - 12th Grade

10 Qs

Topics 7 & 8 - Static Methods/Variables and Null Keyword

Topics 7 & 8 - Static Methods/Variables and Null Keyword

Assessment

Quiz

Computers

12th Grade

Hard

Created by

SAMUEL KEENER

Used 4+ times

FREE Resource

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Media Image

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

Media Image

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

Media Image

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?

  1. A Frog class variable that counts the number of Frog objects that have been made.

  1. A Frog class variable that counts the number of hops a Frog object has performed.

  1. 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

Media Image

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

Media Image

Which of the following can replace /* missing condition */ so that the printDetails method CANNOT cause a run-time error?

  1. I. !borrower.equals(null)

  2. II. borrower != null

  3. III. borrower.getName() != null

I only

II only

III only

I and II

II and III

8.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

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