Exam 9: Using Classes and Objects

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Predefined types such as int, double, and char are all examples of what component of the C# language?

Free
(Multiple Choice)
4.9/5
(45)
Correct Answer:
Verified

B

Write an example method that overrides the + operator to create a new book whose title is a concatenation of the titles of two books.For example, if the first book's title is "The Adventures of Tom Sawyer" and the second book's title is "The Adventures of Huckleberry Finn", the concatenated title will be "The Adventures of Tom Sawyer and The Adventures of Huckleberry Finn".Assume the book class is defined as: class Book { public Book(string title) { Title = title; } public string Title {get; set;} }

Free
(Essay)
4.9/5
(40)
Correct Answer:
Verified

The overwritten method should be similar to the operator+ method shown below.It must be declared as static, take two Book parameters, and provide some mechanism for concatenating the titles of the two books.
public static Book operator+(Book first, Book second)
{
string newTitle = first.Title + " and " +
second.Title;
return(new Book(newTitle));
}

What is the difference between overriding a method and overloading a method with respect to method signatures?

Free
(Essay)
4.9/5
(39)
Correct Answer:
Verified

When a method overrides another, it has the same signature as the method it overrides.When methods are overloaded, they have different signatures.

Like any other C# method, constructors can be overloaded.Show how to create two public constructors-one with no parameters, and one with a parameter called sal-that both set the value for the property Salary within the following class: class Employee { public double Salary; }

(Essay)
5.0/5
(41)

If you don't write a constructor for a class object, C# writes one for you.

(True/False)
4.9/5
(26)

What contains the actions you require when an instance of a class is destroyed, such as when the instance goes out of scope?

(Multiple Choice)
4.8/5
(40)

Briefly describe what an object initializer does and give a specific example.When is the object initializer assignment made?

(Essay)
4.8/5
(33)

Even though you can't specify this modifier for a named constant within a class, what is the effective access modifier for the constant?

(Multiple Choice)
4.9/5
(46)

Besides being known as a class client, what is a class that instantiates objects of another prewritten class known as?

(Multiple Choice)
4.9/5
(36)

A parameter that is undeclared and that gets its value automatically is considered to be what type of parameter?

(Multiple Choice)
4.7/5
(34)

Creating an object requires two steps that are shown in the example below: Employee myAssistant; myAssistant = new Employee(); What do these statements accomplish?

(Essay)
5.0/5
(40)

What kind of property is one in which the code within the accessors is created automatically?

(Multiple Choice)
4.9/5
(31)

What statement regarding the use of destructors is accurate?

(Multiple Choice)
4.9/5
(28)

When you create an array of objects, the array holds the actual value of each of the objects.

(True/False)
4.9/5
(35)

What class access modifier should you utilize to limit access to the assembly (a group of code modules compiled together) to which the class belongs?

(Multiple Choice)
4.8/5
(38)

Only nonstatic methods receive a this reference.

(True/False)
4.9/5
(37)

What class access modifier means that access to the class is not limited?

(Multiple Choice)
4.9/5
(31)

As an alternative to repeating code in multiple constructors, what can be used to indicate that another instance of a class constructor should be executed before any statements in the current constructor body?

(Multiple Choice)
4.7/5
(41)

What consists of abstract methods (and perhaps other members) that can be used by any class, as long as the class overrides the abstract method definitions?

(Multiple Choice)
4.9/5
(37)

What interface in C# contains the definition for the CompareTo() method that compares one object to another and returns an integer?

(Multiple Choice)
4.7/5
(37)
Showing 1 - 20 of 39
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)