chapter 12

¡Supera tus tareas y exámenes ahora con Quizwiz!

interface

A(n) ________ is best used for providing services that bring together objects of otherwise unrelated classes. abstract class concrete class interface None of the above.

true

An abstract base class can be used to declare references. True False

true

An abstract class may be derived from another abstract class. True False

because the derived class is an object of its base class.

Assigning a derived class reference to a base class variable is safe: because the derived class has an object of its base class. because the derived class is an object of its base class. only when the base class is abstract. only when the base class is concrete.

False

Attempting to instantiate an object of an abstract class is a logic error. True False

sealed methods are static.

Classes and methods are declared sealed for all of the following reasons, except: sealed methods allow inlining the code. sealed methods and classes prevent further inheritance. sealed methods are static. sealed methods can improve performance.

All of the above.

Consider the abstract class below: public abstract class Foo { private int a; public int b; public Foo( int aVal, int bVal ) { a = aVal; b = bVal; } // end Foo constructor public abstract int calculate(); } // end class Foo Any concrete subclass that extends class Foo: Must implement a method called calculate. Will not be able to access the instance variable a. Will not be able to instantiate an object of class Foo. All of the above.

it cannot be overridden

Declaring a method sealed means: it will prepare the object for garbage collection it cannot be accessed from outside its class it cannot be overloaded it cannot be overridden

true

If a derived class reference is assigned to a base class variable, the variable must be cast back to the derived class before any derived class methods can be called with it. True False

a reference of the base class that defines the behavior of the object

If a method needs to be called polymorphically, what type of reference should be used to point to the object that the method is being called with? a reference of the base class that defines the behavior of the object a reference of the same type as the object an object reference to the actual object None of the above

execution

Polymorphism allows for specifics to be dealt with during: execution compilation programming debugging

false

Polymorphism allows the addition of classes providing they were at least considered during program development. True False

true

Polymorphism allows you to command a wide variety of objects even if you do not know the objects' types. True False

true

Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically. True False

program in the general.

Polymorphism enables you to: program in the general. program in the specific. absorb attributes and behavior from previous classes. hide information from the user.

a wide variety of classes in a general manner

Polymorphism specifically enables the creation of programs that handle: classes that are containers for other classes large amounts of data with efficiency a wide variety of classes in a general manner None of the above

true

Sealing methods allows the compiler to optimize the program by "inlining code." True False

Both B and C are correct statements.

Select the best true statement: Polymorphism is indicated by a runtime warning from the FCL. Polymorphism is indicated by the use of the keyword virtual in a method signature. Polymorphism is indicated by the use of the keyword override in a method signature. Both B and C are correct statements.

true

The abstract methods and properties of a class do not provide an implementation. True False

prevent overriding and inheritance

The keyword sealed is applied to methods and classes to: prevent overriding and inheritance guarantee an implementation exists specify a class is concrete None of the above.

provide different types of objects with the comparable functionality, even though each will implement the functionality differently

The purpose of an interface is to: provide similar objects with the same functionality, even though each will implement the functionality differently provide different types of objects with the comparable functionality, even though each will implement the functionality differently provide default implementations of methods and properties None of the above.

false

When used correctly, polymorphism will never require changes to be made to any part of the program. True False

public abstract int method1();

Which declaration declares abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)? public int method1(); public int abstract method1(); public abstract int method1(); public int nonfinal method1();

A derived class reference can be assigned to a base class variable, but a base class reference cannot be assigned to a derived class variable.

Which statement best describes the relationship between base class and derived class types? A derived class reference cannot be assigned to a base class variable and a base class reference cannot be assigned to a derived class variable. A derived class reference can be assigned to a base class variable and a base class reference can be assigned to a derived class variable. A base class reference can be assigned to a derived class variable, but a derived class reference cannot be assigned to a base class variable. A derived class reference can be assigned to a base class variable, but a base class reference cannot be assigned to a derived class variable.

false

You may define implementations for abstract methods to act as default implementations. True False


Conjuntos de estudio relacionados

Accounting Books - Journal and Ledger

View Set

Brain and cranial nerves Chap14 (images)

View Set