- Which of the following code snippets about var compile without issue when used in a method? (Choose all that apply.)
- var spring = null;
- var evening = 2; evening = null;
- var night = Integer.valueOf(3);
- var fall = 2, autumn = 2;
- var morning = “”; morning = null;
- Which of the following are correct? (Choose all that apply.)
- An instance variable of type float defaults to 0.
- An instance variable of type char defaults to null.
- A local variable of type double defaults to 0.0.
- A local variable of type int defaults to null.
- A class variable of type String defaults to null.
- A class variable of type String defaults to the empty string “”.
- Which of the following expressions, when inserted independently into the blank line, allow the code to compile? (Choose all that apply.)
public void printMagicData() {
var magic = ;
System.out.println(magic);
}
- 3_1
- Given the following two class files, what is the maximum number of imports that can be removed and have the code still compile?
- Water.java package aquarium; public class Water { }
- Tank.java package aquarium; import java.lang.*; import java.lang.System; import aquarium.Water; import aquarium.*; public class Tank {
public void print(Water water) { System.out.println(water); } }
- 0
- 1
- Which statements about the following class are correct? (Choose all that apply.)
- public class ClownFish {
- int gills = 0, double weight=2;
- void print(int length = 3) {
- System.out.println(gills);
- System.out.println(weight);
- System.out.println(fins);
- System.out.println(length);
- Line 2 generates a compiler error.
- Line 3 generates a compiler error.
- Line 4 generates a compiler error.
- Line 7 generates a compiler error.
- Given the following classes, which of the following snippets can independently be inserted in place of INSERT IMPORTS HERE and have the code compile? (Choose all that apply.)
package aquarium;
public class Water {
boolean salty = false;
}
package aquarium.jellies;
public class Water {
boolean salty = true;
}
package employee;
INSERT IMPORTS HERE
public class WaterFiller {
Water water;
}
- import aquarium.*;
- import aquarium.Water; import aquarium.jellies.*;
import aquarium.jellies.Water;
import aquarium.jellies.*;
import aquarium.jellies.Water;
- None of these imports can make the code compile.
- Which of the following statements about the code snippet are true? (Choose all that apply.)
- int d = numPets.length();
- int e = numGrains.length;
- Line 3 generates a compiler error.
- Line 4 generates a compiler error.
- Line 5 generates a compiler error.
- Line 6 generates a compiler error.
- Line 7 generates a compiler error.
- Line 8 generates a compiler error.
- Which of the following statements about garbage collection are correct? (Choose all that apply.)
- Calling System.gc() is guaranteed to free up memory by destroying objects eligible for garbage collection.
- Garbage collection runs on a set schedule.
- Garbage collection allows the JVM to reclaim memory for other objects.
- Garbage collection runs when your program has used up half the available memory.
- An object may be eligible for garbage collection but never removed from the heap.
- An object is eligible for garbage collection once no references to it are accessible in the program.
- Marking a variable final means its associated object will never be garbage collected.