Question: Code example 15-1 public interface IPrintable { void Print(); } public class Printer { public static void Print(IPrintable p) { MessageBox.Show(Print); p.Print(); } } public

Code example 15-1

public interface IPrintable

{

void Print();

}

public class Printer

{

public static void Print(IPrintable p)

{

MessageBox.Show("Print");

p.Print();

}

}

public class Order : IPrintable

{

public void Print()

{

MessageBox.Show("Order");

}

}

public class Transaction

{

}

public class Rental : Transaction, IPrintable

{

public void Print()

{

MessageBox.Show("Rental");

}

}

5. (Refer to code example 15-1.) Which of the following statements will definitely not compile?

a.

IPrintable p = new Order();

b.

Rental rental = new Rental();

IPrintable p = rental;

c.

IPrintable p = new IPrintable();

d.

Transaction t = new Rental();

6. (Refer to code example 15-1.) What happens when the code that follows is executed?

Rental r = new Rental();

Printer.Print(r);

a.

Print is displayed in a message box.

b.

Rental is displayed in a message box.

c.

Print is displayed in a message box and then Rental is displayed in a second message box.

d.

A runtime error occurs because the Print method cant accept Rental objects.

7. (Refer to code example 15-1.) What happens when the code that follows is executed?

Order order = new Order();

order.Print();

a.

Print is displayed in a message box.

b.

Order is displayed in a message box.

c.

Print is displayed in a message box and then Order is displayed in a second message box.

d.

A runtime error occurs because the Print method cant accept Rental objects.

8. A method that accepts an interface as an argument can accept any object that

a.

implements that interface

b.

defines the same methods as the interface

c.

implements the interface or defines the same methods as the interface

d.

is created from that interface

9. A variable that stores an object that implements an interface can be declared as which of the following data types?

a.

The class that defines the object

b.

The interface that the object implements

c.

Any subclass of the class that defines the object

d.

All of the above

e.

A and C only

10. Which of the following is false about interfaces?

a) An interface describes a set of methods that can be called on an object, providing a

default implementation for the methods.

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

c) Interfaces are useful when attempting to assign common functionality to possibly

unrelated classes.

d) Once a class implements an interface, all objects of that class have an is-a relationship with the interface type.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!