You have files VendingMachine.java, Cola.java, and a driver class named Driver.java. Fill in the correct visibility modifiers so that the comments in the class Cola and Driver’s main method are upheld. public class VendingMachine { 1 void pay() { /*compiles*/ } 2 void shake() { /*compiles*/ } 3 void choose() { /*compiles*/ } } —– in a separate file in a different package/directory —– public class Cola extends VendingMachine { public void cocaCola() { pay(); // doesn’t compile choose(); // compiles }} —– in a separate file in a different package/directory —– public class Driver { public static void main(String[] args) { Cola c = new Cola(); c.pay(); // doesn’t compile c.shake(); // compiles c.choose(); // doesn’t compile }} 1 : [1] 2 : [2] 3 : [3]
Blog
Assume class Child inherits from class Parent. We can instan…
Assume class Child inherits from class Parent. We can instantiate an abstract Child class as long as a concrete Parent class exists by writing the following statement: Child c = new Child();
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: boolean a = new Boolean(true); // 1 occurs Boolean b = a; // 2 occurs 1 : [1] 2 : [2]
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: Character c = ‘b’; // 1 occurschar a = c; // 2 occurs 1 : [1] 2 : [2]
Given the following class hierarchy, identify whether the me…
Given the following class hierarchy, identify whether the method drive is overloaded, overridden, or neither by the subclass: public class Car { public void drive(int miles) { /* implemented */ } } public class Ford extends Car { public void drive(int miles, String name) { /* implemented */ } }
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: Character c = ‘b’; // 1 occurschar a = c; // 2 occurs 1 : [1] 2 : [2]
Given the following class hierarchy, identify whether the me…
Given the following class hierarchy, identify whether the method drive is overloaded, overridden, or neither by the subclass: public class Car { public void drive(int miles) { /* implemented */ } } public class Ford extends Car { public void drive(int miles, String name) { /* implemented */ } }
. ‘ . ‘ .( ‘.) ‘ _ (‘-.)’…
. ‘ . ‘ .( ‘.) ‘ _ (‘-.)’ (`’.) ‘ | (- -(. ‘) WRAPPER (-) ‘ .–`+’-. . (‘ CLASSES ‘) . |`—-‘| (‘ .) – (‘. ) | /..\ | . (‘ `. ) |\./\.\| ` . ` |./G \/| |.\ T/.| `-._/.-‘
Complete the Javadoc comments for the following method: 1…
Complete the Javadoc comments for the following method: 1 Computes the number of hours practiced on an instrument based on the pages of sheet music. 2 sheetMusic The number of pages of music 3 Method returns how long instrument has been played */ public String practice( int sheetMusic ) { return String.format(“Practiced %s for %.2f hours”, this.instrument, sheetMusic * 0.15); } 1 : [1] 2 : [2] 3 : [3]
Complete the Javadoc comments for the following method: 1…
Complete the Javadoc comments for the following method: 1 Computes the number of hours practiced on an instrument based on the pages of sheet music. 2 sheetMusic The number of pages of music 3 Method returns how long instrument has been played */ public String practice( int sheetMusic ) { return String.format(“Practiced %s for %.2f hours”, this.instrument, sheetMusic * 0.15); } 1 : [1] 2 : [2] 3 : [3]