Programming Ch. 10

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

True or False. An interface can contain instance variables

False

True or False. Overriding a method and overloading a method mean the same thing.

False

True or False. Some OOP developers call a subclass the base class and call a superclass the derived class.

False

True or False. The following code will run without errors: // Figure is an abstract class Figure f = new Figure( );

False

True or False. To use polymorphism, the classes must be in a different hierarchy.

False

True or False. When a class extends another class, the default constructor of the subclass automatically calls the default constructor of the superclass. This is called explicit invocation.

False

True or False: A constructor can be declared abstract.

False

True or False: Abstract methods can be private

False

True or False: Abstract methods can be static.

False

True or False. An interface can contain one or more static constants.

True

True or False. If the call to the direct superclass constructor was not the first statement in the constructor, a compiler error will be generated.

True

True or False. Several classes implement an interface, but all of them implement the same method using the same code. To provide a common method for all of these classes, you would create an abstract class.

True

True or False. The extends keyword specifies that the subclass inherits members of the superclass

True

True or False. Typically, an abstract class is a class that is not completely implemented.

True

True or False: Abstract methods can be overridden

True

. True or False: An interface can contain a constructor.

False

Which of the following is true of polymorphism? a. It simplifies the processing of various elements in the same class hierarchy. b. To use polymorphism, the classes must be in a different hierarchy. c. In Greek, the term means "many changes." d. All of these are correct.

a. It simplifies the processing of various elements in the same class hierarchy

Why does using the protected access modifier compromise encapsulation? a. Multiple classes can set the value of an instance variable defined in another class. b. When a class does change a protected value, there is added maintenance complexity. c. Subclass methods that directly set the value of a protected instance variable need to be verified. d. When high performance is essential, superclass methods can be used to change the value of protected variables.

a. Multiple classes can set the value of an instance variable defined in another class.

Why would you want to override a method? a. It allows you to hide features of the subclass using the super keyword. b. It allows you to hide features of the superclass that you want to change. c. It allows you to make the inherited version of the method visible to the client of the subclass. d. It allows you to invoke the base case method

b. It allows you to hide features of the superclass that you want to change.

An abstract method: a. has a "do-nothing" body. b. does not have a body. c. has a body that operates like any other method.

b. does not have a body

Which of the following are not inherited by subclasses? a. public fields and public methods b. private fields and private methods protected fields and protected methods c. All of these are correct

b. private fields and private methods

Which Java keyword do we use in the constructor of a class inheriting from another class if we want to call the constructor of the inherited class? a. call b. super c. constructor d. clone

b. super

Which of the following is correct regarding constructors? a. Constructors are inherited but cannot be accessed. b. Constructors are inherited and can be accessed. c. Constructors are accessible but are not inherited. d. Constructors are not inherited and cannot be accessed

c. Constructors are accessible but are not inherited.

Inheritance is useful for which of the following? a. It declares the hierarchy of methods that are not common to all classes so they can be reused. b. It allows superclasses to override subclasses. c. It allows related classes to be organized into levels of functionality so they can be reused. d. None of these is correct.

c. It allows related classes to be organized into levels of functionality so they can be reused

Which of the following cannot be an interface member? a. A class A constant b. A mutator method c. An abstract method

c. a mutator method

When is it determined which method is called when using polymorphism? a. at compile time b. at the time of writing code c. at runtime

c. at runtime

Which of the following is the correct definition of polymorphism? a. One form only b. Two forms only c. Multiple forms d. No form

c. multiple forms

Why does Java provide a protected access modifier? a. To hide methods from the client classes b. To hide fields from client classes c. So that fields and methods can be inherited by subclasses d. All of these are correct.

d. All of these are correct

True or False. A method in a subclass overriding a method in a superclass cannot call the superclass method.

false


Ensembles d'études connexes

Comprehensive practice exam questions

View Set

All chapters answers call of the wild

View Set

Retirement Planning: Non-Qualified Plans (Module 3)

View Set