chapter 10 MCQ
Abstract methods must be __________. a. overridden b. overloaded c. deleted and replaced with real methods d. declared as private
a. overridden
This key word refers to an object's superclass. a. super b. base c. superclass d. this
a. super
True or False: When a method is declared with the final modifier, it must be overrid-den in a subclass.
false
When you instantiate an anonymous inner class, the class must do one of two things. What are they?
implement an interface or extend another class/superclass
// Superclass public class Vehicle { public abstract double getMilesPerGallon(); (Other methods . . .) } // Subclass public class Car extends Vehicle { private int mpg; public int getMilesPerGallon(); { return mpg; } (Other methods . . .) }
int in subclass doesnt match double in superclass
What are the differences between an abstract class and an interface?
interface can only have abstract methods, abstract class can have both interface can only have final static variables abstract can have final, static, non final, non static interface supports multiple inheritance abstract does not
What is a functional interface?
interface with only one abstract method
When does dynamic binding take place?
run time. dynamic binding means link of function call and definition
True or False: A superclass has a member with package access. A class that is outside the superclass's package but inherits from the superclass can access the member.
true
True or False: The superclass constructor always executes before the subclass constructor.
true
True or False: When a class contains an abstract method, the class cannot be instantiated.
true
All classes directly or indirectly inherit from this class. a. Object b. Super c. Root d. Java
a. Object
In a subclass constructor, a call to the superclass constructor must __________. a. appear as the very first statement b. appear as the very last statement c. appear between the constructor's header and the opening brace d. not appear
a. appear as the very first statement
A functional interface is an interface with __________. a. only one abstract method. b. no abstract methods. c. only private methods. d. no name.
a. only one abstract method.
In an inheritance relationship, this is the general class. a. subclass b. superclass c. slave class d. child class
b. superclass
// Superclass public class Vehicle { private double cost; public Vehicle(double c) { cost = c; } (Other methods . . .) } // Subclass public class Car extends Vehicle { private int passengers; public Car(int p) { passengers = c; } (Other methods . . .) }
c is undeclared in the subclass
Abstract classes cannot __________. a. be used as superclasses b. have abstract methods c. be instantiated d. have fields
c. be instantiated
What is an "is-a" relationship?
has characteristics of general class and unique characteristics
What is an abstract method?
method with no body and expects to be overridden
Can a subclass ever directly access the private members of its superclass?
no
Reference variables can be polymorphic. What does this mean?
reference variable can be the superclass type and reference an object that is the superclass or sublcasses
What is an abstract class?
represents the abstract form of all classes that inherit from it
// Superclass public class Vehicle { (Member declarations . . .) } // Subclass public class Car expands Vehicle { (Member declarations . . .) }
should be extends not expands
True or False: A superclass reference variable can reference an object of a subclass that extends the superclass.
true
True or False: By default all members of an interface are public.
true
True or False: In a subclass, a call to the superclass constructor can only be written in the subclass constructor.
true
What is the difference between overriding a superclass method and overloading a superclass method?
overloading has different parameter list, overrides has the same signature
In an inheritance relationship, this is the specialized class. a. superclass b. master class c. subclass d. parent class
c. subclass
What is the difference between a protected class member and a private class member?
protected has package access private only has class access
A program uses two classes: Animal and Dog . Which class is the superclass and which is the subclass?
super is animal dog is sub
Which constructor is called first, that of the subclass or the superclass?
superclass NOT SUBCLASS
A method in a subclass that has the same signature as a method in the superclass is an example of __________. a. overloading b. overriding c. composition d. an error
b. overriding
A subclass does not have access to these superclass members. a. public b. private c. protected d. all of these
b. private
With this type of binding, the Java Virtual Machine determines at runtime which method to call, depending on the type of the object that a variable references. a. static b. early c. flexible d. dynamic
d. dynamic
An anonymous inner class must __________. a. be a superclass b. implement an interface c. extend a superclass d. either b or c.
d. either b or c.
This key word indicates that a class inherits from another class. a. derived b. specialized c. based d. extends
d. extends
What is the superclass and what is the subclass in the following line? public class Pet extends Dog
dog is super pet is sub
True or False: A class may only implement one interface.
false
True or False: A subclass reference variable can reference an object of the superclass.
false
True or False: An object of a superclass can access members declared in a subclass.
false
True or False: Constructors are not inherited.
false
True or False: If a subclass constructor does not explicitly call a superclass construc-tor, Java will not call any of the superclass's constructors.
false
A method in a subclass having the same name as a method in the superclass but a different signature is an example of __________. a. overloading b. overriding c. composition d. an error
a. overloading
When a class implements an interface, it must __________. a. overload all of the methods listed in the interface b. provide all of the nondefault methods that are listed in the interface, with the exact signatures and return types specified c. not have a constructor d. be an abstract class
b. provide all of the nondefault methods that are listed in the interface, with the exact signatures and return types specified
Fields in an interface are __________. a. final b. static c. both final and static d. not allowed
c. both final and static
You can use a lambda expression to instantiate an object that __________. a. that has no constructor. b. extends any superclass. c. implements a functional interface d. does not implement an interface.
c. implements a functional interface
This operator can be used to determine whether a reference variable references an object of a particular class. a. isclass b. typeof c. instanceof d. isinstance
c. instanceof
You use the __________ operator to define an anonymous inner class. a. class b. inner c. new d. anonymous
c. new
These superclass members are accessible to subclasses and classes in the same package. a. private b. public c. protected d. all of these
c. protected
The following is an explicit call to the superclass's default constructor. a. default(); b. class(); c. super(); d. base();
c. super();
// Superclass public class Vehicle { private double cost; (Other methods . . .) } // Subclass public class Car extends Vehicle { public Car(double c) { cost = c; } }
cost is private in the Superclass subclass has no access
What is a lambda expression?
expressions that creates an object and implements an interface and overrides its abstract methods