C# FinaL Ch. 12

Ace your homework & exams now with Quizwiz!

Which is used to specify that a class will be implementing an interface?

:

Which statement best describes the relationship between base class and derived class types?

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:

All of the above.

Which of the following is false about interfaces?

An interface describes a set of methods that can be called on an object, providing a default implementation for the methods.

T/F A class that implements an interface may not act as a base class for other classes.

False. A class that implements an interface may be inherited by derived classes.

T/F All methods in a sealed class must be explicitly declared sealed.

False. All methods in a sealed class are implicitly sealed.

T/F All methods in an abstract class are inherently abstract.

False. An abstract class also may contain instance data and non-abstract methods.

T/F An abstract class cannot have instance data and non-abstract methods.

False. An abstract class can have instance data and non-abstract meth¬ods.

T/F The abstract keyword has the same effect as the virtual keyword.

False. An abstract method has no implementation and must be overridden while a virtual method provides an implementation and the option of being overridden.

T/F An interface can not provide properties with get and set accessors.

False. An interface can provide properties with get and set accessors.

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

False. Attempting to provide an implementation for an abstract method is a syntax error.

T/F Declaring an interface protected allows for extra security precautions.

False. Declaring an interface private or protected is an error.

T/F If a class leaves one method in an interface undeclared, the class is implicitly declared by C# as an abstract class.

False. If a class leaves one method in an interface undeclared, the class becomes an abstract class and must explicitly be declared abstract in the first line of its class declaration.

T/F Objects of abstract base classes can be instantiated.

False. Only objects of concrete classes can be instantiated.

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

False. Parts of a program that need modification are those that require direct knowledge of the particular class that's added to the hierarchy.

T/F Unfortunately, polymorphic programs make it difficult to add new capabilities to a system.

False. Polymorphic programs make it easy to add new capabilities to a system.

T/F The major drawback to polymorphically designed programs is that they do not take into account the future addition or deletion of classes.

False. Polymorphically designed programs are extremely extensible and easily handle new classes that extend the same hierarchy of classes processed by the program.

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

False. Polymorphism can be used to include classes that were not even envisioned during program development.

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

False. This is a compilation error.

Every object in C# knows its own class and can access this information through method_________ .

GetType()

By convention, the name for a Car interface is:

ICar

________ code is the process by which the compiler replaces method calls with the code of a method to improve performance.

Inlining

T/F A concrete class that implements an interface must define all methods and properties of that interface.

True

T/F Abstract classes can provide data and services for objects.

True

T/F All static and private methods are implicitly sealed.

True

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

True

T/F An interface is typically used in place of an abstract class when there is no default implementation to inherit.

True

T/F An interface reference may invoke only the methods that the interface declares.

True

T/F At least one argument of an operator overload method must be a reference to an object of the class in which the operator is overloaded.

True

T/F Concrete classes provide implementations for every method and property they define.

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 Methods that overload binary operators must take two arguments.

True

T/F Operators should be overloaded to perform actions similar to those that they normally perform on objects of simple types.

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 Polymorphism helps promote software extensibility.

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 When a request is made to use a derived-class-object method through a base-class reference, C# polymorphically chooses the correct overridden method in the appropriate derived class that's associated with the object.

True

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

True.

T/F Operator is returns true if two matching types are being compared.

True.

T/F Polymorphism allows classes to be added with little or no modifications to the generic portion of a program.

True.

All of the following methods are implicitly sealed except:

a method in an abstract class.

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

Polymorphism specifically enables the creation of programs that handle:

a wide variety of classes in a general manner

A class that implements an interface but does not declare all of the interface's methods must be declared:

abstract

Which of the following statements about abstract base classes is true?

abstract base classes may contain data.

Which of the following characteristics could be used to create an interface for a file, a cat and a house?

age

Interfaces can have___________ methods.

any number of

Assigning a derived class reference to a base class variable is safe:

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

Which of the following does not complete the sentence correctly? An interface .

can be instantiated.

If an app needs to perform a derived-class-specific operation on a derived class object reference by a base class variable, the app must first cast the base class reference to a derived class reference through a technique known as _________.

downcasting

Operator overloading is the process of:

enabling C#'s operators to work with class objects

Polymorphism allows for specifics to be dealt with during:

execution

Abstract classes may not be:

instantiated

A(n) ________ is best used for providing services that bring together objects of otherwise unrelated classes.

interface

If the base class contains only abstract method declarations, the base class is used for:

interface inheritance.

Declaring a method sealed means:

it cannot be overridden

A convention of the UML is to denote the name of an abstract class in:

italics

Keyword _______ is used to indicate a method overloads a specific operator.

operator

The keyword sealed is applied to methods and classes to:

prevent overriding and inheritance

Polymorphism enables you to:

program in the general.

The purpose of an interface is to:

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

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

public abstract int method1();

Classes and methods are declared sealed for all of the following reasons, except:

sealed methods are static.

Constants declared in an interface are implicitly _______.

static

Overloaded operator methods must be declared public and ________.

static

Polymorphism involves:

the same message sent to a variety of objects, which each interpret their own way


Related study sets

CHEM 1113- Ch. 4 Homework (Chemical Reactions & Aqueous Solutions)

View Set

Legal Concepts of the Insurance Contract

View Set

Domain IV: Therapeutic Intervention

View Set

chapter 65 management of patients with oncologic or degenerative neurologic disorders

View Set

Chapter 42: Circulation and Gas Exchange

View Set