TINFO Quiz 12

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which statement best describes the relationship between base class and derived class types? A) 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. B) 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. C) 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. D) 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.

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: A) Must implement a method called calculate. B) Will not be able to access the instance variable a. C) Will not be able to instantiate an object of class Foo. D) All of the above.

All of the above

Select the best true statement

Both B and C are correct statements.

T/F Attempting to instantiate an object of an abstract class is a logic error.

False

T/F Polymorphism allows the addition of classes providing they were at least considered during program development.

False

T/F When used correctly, Polymorphism will never require changes to be made to any part of the program.

False

T/F You may define implementations for abstract methods to act as default implementations

False

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

Sealed methods are static

T/F An abstract class may be derived from another abstract class.

True

T/F 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

T/F Polymorphism allows you to command a wide variety of objects even if you do not know the objects' types.

True

T/F Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically

True

T/F Sealing methods allows the compiler to optimize the program by "inlining code."

True

T/F The abstract methods and properties of a class do not provide an implementation

True

T/F an abstract base class can be used to declare references

True

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) a reference of the abstract class that defines the behavior of the object B) a reference of the same type as the object C) an object reference to the actual object D) None of the above.

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

Polymorphism specifically enables the creation of programs that handle: A) classes that are containers for other classes B) large amounts of data with efficiency C) a wide variety of classes in a generic manner D) None of the above

a wide variety of classes in a general manner

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

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

Polymorphism allows for specifics to be dealt with during: A) execution B) programming C) debugging D) compilation

execution

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

interface

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

it cannot be overridden

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

prevent overriding and inheritance

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

program in the general.

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

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

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

public abstract int method1();


संबंधित स्टडी सेट्स

Quiz 9/3: Social Security Benefits and Taxation

View Set

Criminal Justice Studies Midterm Exam 2023

View Set

CFA Level 1 - Section 2: Quantitative Methods - Reading 10 and 11: Probability and Sampling

View Set

Calculus Antiderivatives Unit (4.9-)

View Set

MGT-102 Principles of Management Chapters 5-

View Set