Docsity

Object-Oriented Programming Quiz: Inheritance, Polymorphism, and Class Relationships, Exams of Advanced Education

Toggle sidebar
bg1
MODULO 9 โ€“ QUIZ REVISION UPDATE
Assume that the Vehicle class contains a virtual method named CalculateMaxSpeed().
Assume that both the MotorVehicle and Automobile classes override this method.
Which class defines the method that is called when the second statement in the code
that follows is executed?
MotorVehicle car = new Automobile();
car.CalculateMaxSpeed(); - Automobile
A class can - be both a base class and a derived class
If a method accepts an Object type, what types of objects can it accept? - All objects
In the System.Windows.Forms namespace, the Control class - provides properties and
methods that all controls in the namespace have in common
Which of the following declarations defines a Student class that inherits a Person class?
- public class Student : Person
(Refer to diagram 14-1.) If the constructor that follows is called, what other constructor
is also called?
public Sailboat(string id, decimal length, int sails) : base(id, "sailboat", length)
{
this.sails = sails;
} - public WaterCraft(string id, string type, decimal length){...}
Which of the following is not a reason to declare a class as sealed? - To give a class
more functionality
Which of the following method declarations overrides the method that follows?
protected virtual double CalculateMilesPerGallon(double speed){...} - public override
double CalculateMilesPerGallon(double s){...}
What type of class can be inherited by another class but can't be instantiated directly? -
an abstract class
If the Student class inherits the Person class and overrides a virtual method named
GetBirthday(), what feature does the following code example illustrate?
Student s = new Student("Albert Einstein");
Person p = s;
p.GetBirthday(); - Polymorphism
pf3

Partial preview of the text

Download Object-Oriented Programming Quiz: Inheritance, Polymorphism, and Class Relationships and more Exams Advanced Education in PDF only on Docsity!

MODULO 9 โ€“ QUIZ REVISION UPDATE

Assume that the Vehicle class contains a virtual method named CalculateMaxSpeed(). Assume that both the MotorVehicle and Automobile classes override this method. Which class defines the method that is called when the second statement in the code that follows is executed? MotorVehicle car = new Automobile(); car.CalculateMaxSpeed(); - Automobile A class can - be both a base class and a derived class If a method accepts an Object type, what types of objects can it accept? - All objects In the System.Windows.Forms namespace, the Control class - provides properties and methods that all controls in the namespace have in common Which of the following declarations defines a Student class that inherits a Person class?

  • public class Student : Person (Refer to diagram 14-1.) If the constructor that follows is called, what other constructor is also called? public Sailboat(string id, decimal length, int sails) : base(id, "sailboat", length) { this.sails = sails; } - public WaterCraft(string id, string type, decimal length){...} Which of the following is not a reason to declare a class as sealed? - To give a class more functionality Which of the following method declarations overrides the method that follows? protected virtual double CalculateMilesPerGallon(double speed){...} - public override double CalculateMilesPerGallon(double s){...} What type of class can be inherited by another class but can't be instantiated directly? - an abstract class If the Student class inherits the Person class and overrides a virtual method named GetBirthday(), what feature does the following code example illustrate? Student s = new Student("Albert Einstein"); Person p = s; p.GetBirthday(); - Polymorphism

The ToString(), Equals(), and GetHashCode() methods are available to all objects because they are - members of the System.Object class, which all objects inherit ode example 14- public class SavingsAccount : Account { public SavingsAccount() : base() { base.Type = "Savings"; } public SavingsAccount(int number) : base(number) { base.Type = "Savings"; } public SavingsAccount(int number, decimal balance) : base(number, "Savings", balance) { } } (Refer to code example 14-1.) Which of the following statements creates an object of the Account class? - Account account = new Account(111, "Checking", 0.0m); The GetType() method of an object returns - a Type object that contains information about the object's type What type of class can't be inherited by another class? - a sealed class A protected method defined within a base class is available to - both the base class and classes derived from it If the Student class inherits the Person class and overrides a virtual method named GetBirthday(), which method does the third statement in the following code example call? Student s = new Student("Albert Einstein"); Person p = s; p.GetBirthday(); - the GetBirthday() method defined in the Student class Which of the following operators can you use to test if an object has a specific type? - typeof Which keyword do you use to declare a method or property that can be overridden by a derived class? - virtual