Question
MULTIPLE CHOICE [Answers are in tables delete all but the correct answers cell] 1. Which of the following methods can always be called from a
MULTIPLE CHOICE [Answers are in tables delete all but the correct answers cell]
1. Which of the following methods can always be called from a Product object?
b. toString
2. To compare the instance Explicit casting is always required to cast
a. a superclass object to a subclass object
b. a subclass object to a superclass object
c. both A and B
d. neither A nor B
3. variables of two objects, you can
b. override the equals method of the Object class
4. To check if an object is created from the specified class, you can use
a. the createdFrom keyword
b. the instanceof keyword
c. the isTypeOf method
d. the equals method
5. When a subclass that is not declared as abstract inherits an abstract class,
a. it must override all of the methods in the abstract class
b. it must override all of the abstract methods in the abstract class
c. it must override all of the final methods in the abstract class
d. it cant override any of the methods in the abstract class
6. You can use the final keyword
a. to prevent a class from being inherited
b. to prevent a method from being overridden
c. to prevent a method from assigning a new value to a parameter
d. all of the above
e. none of the above
7. Which of the following method declarations overrides this method?
double calculateMilesPerGallon(double speed){...}
a. double calculateMilesPerGallon(int speed){...}
b. double calculateMilesPerGallon(double s){...}
c. double calculateMilesPerGallon(double speed, int r){...}
d. double calculate(double speed){...}
Inheritance hierarchy 11-1
8. (Refer to inheritance hierarchy 11-1.) If the constructor that follows is called, it calls a constructor from which class?
public Sailboat(int sails) {
super();
this.sails = sails;
}
a. Sailboat
b. Canoe
c. WaterCraft
d. Vehicle
9. (Refer to inheritance hierarchy 11-1.) If the MotorVehicle class contains a protected method named getEngineType, what other class or classes can access this method?
a. Vehicle, Automobile, and Motorcycle d. Vehicle
b. Vehicle and WaterCraft e. no other classes can access it
c. Automobile and Motorcycle
10. If the Point class doesnt override the equals method in the Object class, what will the following code do?
Point pointOne = new Point(3, 4);
Point pointTwo = new Point(3, 4);
System.out.println(pointOne.equals(pointTwo));
a. Cause a compile-time error since the equals method doesnt exist in the Point class
b. Cause a compile-time error since the equals method cant accept a Point object
c. Print true to the console
d. Print false to the console
11. If a method accepts an Object object, what other types of objects can it accept?
a. None
b. All objects
c. Only objects from the Java API classes
d. Only objects from classes that explicitly extend the Object class
12. If the Loan class contains a final method named calculatePayment, what does the following code do?
HomeLoan loan = new HomeLoan(amount, months);
loan.calculatePayment();
a. Causes a compile-time error
b. Throws an exception
c. Calls the calculatePayment method in the HomeLoan class
d. Calls the calculatePayment method in the Loan class
13. Which of the following can you not code in a subclass?
a. a method with the same signature as a method in the superclass
b. a call to a constructor of the superclass
c. a method thats not defined by the superclass
d. a call to a private method of the superclass
14. What keyword do you use in a class declaration to create a subclass?
a. extends c. overrides
b. inherits d. overloads
15. What feature allows you to treat an Admin object as though it were an Account object in this inheritance hierarchy?
a. polymorphism
b. garbage collection
c. encapsulation
d. instantiation
e. abstraction
16. What class or classes is a variable available to if it is declared without an access modifier?
a. All classes in the same package
b. All classes in the same package and to subclasses
c. All classes in all packages
d. Only the current class
17. What class or classes is a method that is declared protected available to?
a. All classes in the same package
b. All classes in the same package and to subclasses
c. All classes in all packages
d. The current class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started