Analyze the following code and indicate, for each line, whether autoboxing, unboxing, or neither occurs when the assignment operator is evaluated: Double a = 20.5; // 1 occurs double b = a; // 2 occurs 1 : [1] 2 : [2]
Category: Uncategorized
Fill in the blanks to implement the toString method. public…
Fill in the blanks to implement the toString method. public class Flag { private double height; private double width; private String color; public 1 toString( 2 ) { 3 }} 1 :[1] 2 :[2] 3 :[3]
Analyze the following code and indicate, for each line, whet…
Analyze the following code and indicate, for each line, whether autoboxing, unboxing, or neither occurs when the assignment operator is evaluated: Double a = 20.5; // 1 occurs double b = a; // 2 occurs 1 : [1] 2 : [2]
public class Genre { public Genre() { System.out.println…
public class Genre { public Genre() { System.out.println(“GENRE”); }}public class MusicGenre extends Genre { public MusicGenre() { System.out.println(“MUSIC”); }}public class Rock extends MusicGenre { public Rock () { super(); System.out.println(“ROCK”); }} Given the class definitions above, what is printed to the console when the following lines of code are executed? Assume the code compiles and runs (i.e. ignore typos). MusicGenre g = new MusicGenre();Rock s = new Rock();
You have files Dessert.java, BlueberryMuffin.java, and a dri…
You have files Dessert.java, BlueberryMuffin.java, and a driver class named Driver.java. Fill in the correct visibility modifiers so that the comments in the class BlueberryMuffin and Driver’s main method are upheld. public class Dessert { 1 void eat() { /*compiles*/ } 2 void split() { /*compiles*/ } 3 void purchase() { /*compiles*/ } } —– in a separate file in a different package/directory —– public class BlueberryMuffin extends Dessert { public void nom() { split(); // doesn’t compile purchase(); // compiles }} —– in a separate file in a different package/directory —– public class Driver { public static void main(String[] args) { BlueberryMuffin b = new BlueberryMuffin(); b.eat(); // compiles b.split(); // doesn’t compile b.purchase(); // doesn’t compile }} 1 : [1] 2 : [2] 3 : [3]
Fill in the blanks to implement the toString method. public…
Fill in the blanks to implement the toString method. public class Flag { private double height; private double width; private String color; public 1 toString( 2 ) { 3 }} 1 :[1] 2 :[2] 3 :[3]
public class Game { public Game() { System.out.println(“…
public class Game { public Game() { System.out.println(“GAME”); }}public class BoardGame extends Game { public BoardGame () { System.out.println(“BOARDGAME”); }}public class Chess extends BoardGame { public Chess () { super(); System.out.println(“CHESS”); }} Given the class definitions above, what is printed to the console when the following lines of code are executed? Assume the code compiles and runs (i.e. ignore typos). BoardGame p = new BoardGame();Chess c = new Chess();
You have files Dessert.java, BlueberryMuffin.java, and a dri…
You have files Dessert.java, BlueberryMuffin.java, and a driver class named Driver.java. Fill in the correct visibility modifiers so that the comments in the class BlueberryMuffin and Driver’s main method are upheld. public class Dessert { 1 void eat() { /*compiles*/ } 2 void split() { /*compiles*/ } 3 void purchase() { /*compiles*/ } } —– in a separate file in a different package/directory —– public class BlueberryMuffin extends Dessert { public void nom() { split(); // doesn’t compile purchase(); // compiles }} —– in a separate file in a different package/directory —– public class Driver { public static void main(String[] args) { BlueberryMuffin b = new BlueberryMuffin(); b.eat(); // compiles b.split(); // doesn’t compile b.purchase(); // doesn’t compile }} 1 : [1] 2 : [2] 3 : [3]
public abstract class Landmark { public abstract int countVi…
public abstract class Landmark { public abstract int countVisitors();} Consider the class shown above. Which of the following class definitions will NOT compile?
Given 3 classes (Tulip, Flower, and Plant), Tulip can inher…
Given 3 classes (Tulip, Flower, and Plant), Tulip can inherit from both Flower and Plant with the following syntax: public class Tulip extends Flower, Plant { /* valid class definition */}