Final Ch 10-12

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which is used to specify that a class will be implementing an interface? -using -: -implements -extends

:

Which of the following statements is false? -A derived class is generally larger than its base class. -A base class object is a derived class object. -The class following the ":"in a class declaration is the direct base class of the class being declared. -C# does not support multiple inheritance.

A base class object is a derived class object.

_________ displays the variables and methods for all classes in a project. -Class View -Object Browser -Design View -None of the above.

Class View

(True/False) An attempt by a method which is not a member of a particular class to access a private member of that class is a fatal runtime error.

False

(True/False) An object of one class cannot be an object of another class.

False

(True/False) Attempting to modify a readonly instance variable after it's initialized is a fatal execution-time error.

False

(True/False) C# is like C++ in that programmers must manage memory explicitly.

False

(True/False) Data members declared as readonly must be initialized in their declaration.

False

(True/False) Every object of a base class is an object of that class's derived classes.

False

(True/False) If a base class constructor is overridden, the original constructor can no longer be called explicitly by the derived class.

False

(True/False) If a class leaves one method in an interface undeclared, the class is implicitly declared by C# as an abstract class.

False

(True/False) Inheritance is the process of building a class with object references of other classes.

False

(True/False) Method Equals will accurately compare any two objects.

False

(True/False) Multiple inheritance, widely used in C#, is the process of inheriting from more than one class.

False

(True/False) Only certain objects have a this reference.

False

(True/False) Only the first constructor for a class is defined without a return value. Subsequent constructors have the return type void.

False

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

False

(True/False) The garbage collector looks for objects with no values.

False

(True/False) To enhance performance and reduce errors, it's a good idea to make derived classes larger than they need to be.

False

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

False

(True/False) You cannot validate values assigned to properties using an object initializer.

False

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

False

By convention, the name for a Car interface is: -InterfaceCar -ICar -CarI -None of the above.

ICar

Which of the following statements is true? -Methods and instance variables can be public, protected or private. -Information hiding is achieved by restricting access to class members via keyword public. -The public members of a class are not directly accessible to the client of a class. -None of the above is true.

Methods and instance variables can be public, protected or private.

(True/False) A base class is often designed by factoring out commonalities among a set of classes.

True

(True/False) A constructor may not have a return value.

True

(True/False) All classes in C# have object as either a direct or indirect base class.

True

(True/False) An object initializer calls the default constructor before executing.

True

(True/False) An object initializer list cannot be empty.

True

(True/False) An object of a class that has a reference to another object of the same class may access all the private data and methods of that class.

True

(True/False) 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

(True/False) Concrete classes provide implementations for every method and property they define.

True

(True/False) Constructors are not inherited.

True

(True/False) Developers use the Object Browser to learn about the functionality provided by a specific class.

True

(True/False) Objects can hide their implementation from other objects.

True

(True/False) Operator is returns true if two matching types are being compared.

True

(True/False) Operators should be overloaded to perform actions similar to those that they normally perform on objects of simple types.

True

(True/False) The data components of a class are called instance variables.

True

(True/False) The public methods of a class present the services that a class provides.

True

(True/False) Variables that are static have class scope.

True

(True/False) When a base class method is overridden in a derived class, it is common to have the derived class version call the base class version and do some additional work.

True

(True/False) You cannot determine when the garbage collector will execute.

True

(True/False) this is often used to distinguish between a local variable and class variable that share an identical name.

True

Instance variables declared readonly do not or cannot: -use the principle of least privilege -be initialized -be modified once the object is constructed -cause syntax errors if used as a left-hand value

be modified once the object is constructed

Which of the following does not complete the sentence correctly? An interface _________. -forces classes that implement it to declare all the interface methods. -is used in place of an abstract class when there is no default implementation to inherit. -cannot be instantiated. -can be instantiated.

can be instantiated.

The use of references to objects of preexisting classes as members of new objects is called . -inheritance -composition -polymorphism -None of the above.

composition

Operator overloading is the process of: -enabling C#'s operators to work with class objects -using operators to create new classes -using operators to specify which versions of overloaded methods to -use -None of the above.

enabling C#'s operators to work with class objects

Object orientation uses classes to: -develop algorithms -encapsulate data and methods -organize large amounts of data -None of the above.

encapsulate data and methods

Which of the following pairs demonstrates the has-a relationship between the first and the second terms? -car, vehicle -house, window -teacher, person -None of the above

house, window

A class inherited from two or more levels up in the hierarchy is known as a . -indirect base class -direct base class -superclass -None of the above

indirect base class

If the base class contains only abstract method declarations, the base class is used for: -implementation inheritance -interface inheritance -Both -Neither

interface inheritance

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

it cannot be overridden

Object initializers (which initialize an object and its properties) use what syntax? -new className(property1 -> value1, ...); -new className(property1 = value1, ...); -new className{property1 = value1, ...}; -className{property1 = value1, ...};

new className{property1 = value1, ...};

An instance of a user-defined type is called a(n) . -class -interface -object -None of the above.

object

Keyword _______ is used to indicate a method overloads a specific operator. -implement -operator -overload -op

operator

A derived class cannot access the _________ members of its base class. -private -static -protected -None of the above.

private

Base class methods with this level of access cannot be called from derived classes. -private -public -protected -package

private

Which base class members are inherited by all derived classes of that base class? -private instance variables and methods -protected instance variables and methods -private constructors -protected constructors

protected instance variables and methods

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();

public abstract int method1();

The _________ of a class are also called the public services or the public interface of the class. -public constructors -public instance variables -public methods -All of the above

public methods

Keyword _________ is used for constants whose values cannot be determined at compile time. -const -readonly -static -None of the above.

readonly

Failure to release resources when the program is no longer using them can cause ________. -buffer overflows -resource leaks -exceptions -None of the above.

resource leaks

Overloaded operator methods must be declared public and ________. -sealed -protected -static -None of the above.

static

Constants declared in an interface are implicitly _______. -private. -static. -abstract. -All of the above.

static.

An object's this reference refers to: -the object itself -what the programmer assigned to this -the entry point of the program -None of the above.

the object itself

Which of the following class members should usually be private? -methods -constructors -variables -All of the above

variables

The default Equals implementation determines: -whether two references refer to the same object in memory. -whether two references have the same type. -whether two objects have the same instance variables. -whether two objects have the same instance variable values.

whether two references refer to the same object in memory.

(True/False) A constructor should return either true or false to determine if the object was initialized properly.

False

(True/False) A derived class is often larger and more general than its base class.

False

(True/False) A program contains a separate copy of a static variable for each object that's instantiated.

False

(True/False) An abstract class cannot have instance data and non-abstract methods.

False

Consider the statement: throw new ArgumentOutOfRangeException(0); Which of the following statements is false? -For values outside proper ranges, an app can throw an exception of type ArgumentOutOfRangeException (namespace System), which notifies the client code that an invalid argument was passed to the method. -This throw statement creates a new object of type ArgumentOutOfRangeException. -The parentheses following the class name indicate a call to the ArgumentOutOfRangeException constructor. -After the exception object is created, the statement after the throw statement is executed this is called the resumption model of exception handling.

After the exception object is created, the statement after the throw statement is executed this is called the resumption model of exception handling.

Composition: -Is a form of software reuse. -Is using an object reference as a class member. -Is a good design practice. -All of the above.

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; } public abstract int calculate(); } 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.

All of the above.

The Object Browser _____________. -lists all the classes in the C# library -describes the functionality provided by a specific class -is separated into 3 frames -All of the above.

All of the above.

Which statement is true when a base class has protected instance variables? -A derived class object can assign an invalid value to the base class's instance variables, thus leaving the object in an inconsistent state. -Derived class methods are more likely to be written so that they depend on the base class's data implementation. -We may need to modify all the derived classes of the base class if the base class implementation changes. -All of the above.

All of the above.

(True/False) A "copy-and-paste" approach is a simple and efficient way from a software-engineering perspective of providing functionality that exists in other classes.

False

(True/False) A base class may have only one derived class.

False

(True/False) A class that implements an interface may not act as a base class for other classes.

False

Complex numbers have the form: realPart + imaginaryPart * i where i is the square root of -1. Which of the following statements is false? -C#'s simple numeric types are value types. -To mimic the simple numeric types, we can define ComplexNumber as a value type by using a struct (short for "structure") rather than a class. -C#'s simple types like int and double are actually aliases for struct types. -Microsoft recommends using structs for most new types, but recommends a class if the type represents a single value.

Microsoft recommends using structs for most new types, but recommends a class if the type represents a single value.

Every class inherits directly or indirectly from class _________. -Inheritor -Base -Super -Object

Object

Overriding a method differs from overloading a constructor because: -For an overloaded constructor, the base class constructor will always be called first. -For an overridden constructor, the base class constructor will always be called first. -Overloaded methods have the same signature. -Overridden methods have the same signature.

Overridden methods have the same signature.

How can a derived class call a base class constructor? -implicitly -explicitly -a and b -the derived class cannot call the base class constructor

a and b

Which of the following statements is true? Constructors: -initialize instance variables -when overloaded, can have identical argument lists -when overloaded, are selected by number and types of parameters -a and c

a and c

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

abstract

When should a program explicitly use the this reference? -accessing a private variable -accessing a public variable -accessing a local variable -accessing a field that is shadowed by a local variable

accessing a field that is shadowed by a local variable

Which of the following characteristics could be used to create an interface for a file, a cat and a house? -door -tail -age -None of the above.

age


Kaugnay na mga set ng pag-aaral

Network+ Practice test Questions

View Set

Camera Shots, Angles, Movement - AICE Media Studies

View Set

Chapter 4 - Patient and Caregiver Teaching

View Set

Demand and Supply Discussion Questions

View Set