Analyze the following code and indicate, for each line, whether autoboxing, unboxing, or neither occurs when the assignment operator is evaluated: Boolean b = true; // 1 occursboolean a = b; // 2 occurs 1 : 2 :
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 */}
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();
public abstract class Dessert { public abstract void eat();…
public abstract class Dessert { public abstract void eat(); } Consider the class shown above. Which of the following class definitions will NOT compile?
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?
. ‘ . ‘ .( ‘.) ‘ _ (‘-.)’…
. ‘ . ‘ .( ‘.) ‘ _ (‘-.)’ (`’.) ‘ | (- -(. ‘ ABSTRACT (-) ‘ .–`+’-. . (‘ CLASSES ‘) . |`—-‘| (‘ .) – (‘. ) | /..\ | . (‘ `. ) |\./\.\| ` . ` |./G \/| |.\ T/.| `-._/.-‘
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();
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?
Noodle n1 = new Pasta(); Noodle n2 = new Ramen(); Pasta p…
Noodle n1 = new Pasta(); Noodle n2 = new Ramen(); Pasta p = new Pasta(); Ramen r = new Ramen(); For the class hierarchy and declarations above, correctly indicate whether each of the following statements will compile and what will happen at runtime (runs correctly or runtime exception). It may be helpful to use scratch paper to keep track of each variable’s static and dynamic type. 1 Noodle noodle = (Noodle) r; 2 Ramen r1 = (Ramen) n1; 3 Ramen r2 = (Ramen) p; 4 Ramen r3 = (Ramen) n2; 1 : 2 : 3 : 4 :
public abstract class Athlete { public abstract void compete…
public abstract class Athlete { public abstract void compete();} Consider the class shown above. Which of the following class definitions will NOT compile?