Consider the following code snippet: public class Motorcycle extends Vehicle { . . . public Motorcycle(int numberAxles) { super(numberAxles); //line #1 } } If the line marked “//line #1” was missing, which of these statements would be correct?
Blog
Consider the following class hierarchy: public class Vehicle…
Consider the following class hierarchy: public class Vehicle { private String type; public Vehicle(String type) { this.type = type; } public String displayInfo() { return type; } } public class LandVehicle extends Vehicle { public LandVehicle(String type) { super(type); } } public class Auto extends LandVehicle { public Auto(String type) { _________; } } Complete the code in the Auto class constructor to store the type data.
Which of the following can potentially be changed by a Java…
Which of the following can potentially be changed by a Java method?
Judging by the name of the method, which of the following me…
Judging by the name of the method, which of the following methods would most likely be a mutator method?
Consider the following code snippet: public interface Measur…
Consider the following code snippet: public interface Measurable { double getMeasure(); ____________ double sum(Measurable[] objects) { // implementation to compute the sum of the Measurable objects } } Which of the following completes the interface declaration correctly?
Consider the classes shown below: public class Parent { priv…
Consider the classes shown below: public class Parent { private int value = 100; public int getValue() { return value; } } public class Child extends Parent { private int value; public Child(int number) { value = number; } } What is the output of the following lines of code? Child kid = new Child(-14); Parent adult = new Parent(); System.out.println(kid.getValue() + ” ” + adult.getValue());
Mutator methods exhibit which of the following types of side…
Mutator methods exhibit which of the following types of side effect?
Which of the following describes an immutable class?
Which of the following describes an immutable class?
Using the given definition of the Measurable interface: publ…
Using the given definition of the Measurable interface: public interface Measurable { double getMeasure(); } Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method: Measurable m = new Measurable(); System.out.println(m.getMeasure()); Which of the following statements is true?
Select an appropriate expression to complete the following m…
Select an appropriate expression to complete the following method, which is designed to return the number of elements in the parameter array numbers. If a value appears more than once, it should be counted exactly once. public static int countElementsOnce(int[] numbers) { Set values = new HashSet(); for (int num: numbers) { values.add(num); } ______________________ }