bowtietigers
Test por , creado hace más de 1 año

Review for chapter 9, which is on interfaces.

394
0
0
bowtietigers
Creado por bowtietigers hace casi 9 años
Cerrar

Chapter 9 Review

Pregunta 1 de 10

1

Which of the following choices might serve as an interface for the other choices listed?

Selecciona una de las siguientes respuestas posibles:

  • Piano

  • Drum

  • Guitar

  • Instrument

  • FrenchHorn

Explicación

Pregunta 2 de 10

1

Which of the following code segments causes a compile-time error?

Selecciona una de las siguientes respuestas posibles:

  • Airplane boeing707 = new Airplane();

  • Flier boeing707 = new Flier();

  • Flier boeing707 = new Airplane();

  • Airplane boeing707 = new Airplane();
    Flier airTraveler = boeing707;

  • Airplane boeing707 = new Airplane();
    Flier airTraveler;
    airTraveler = (Airplane) beoing707;

Explicación

Pregunta 3 de 10

1

Consider the following code segment.
1 Airplane skyRider = new Airplane();
2 Flier skyRider2 = skyRider;
3 Athlete skyRider3 = (Athlete) skyRider2;
4 Airplane skyRider4 = (Airplane) skyRider2;
5 Flier skyRider5 = skyRider4;
Which statement above will cause a run-time error and throw an exception?

Selecciona una de las siguientes respuestas posibles:

  • Statement 1

  • Statement 2

  • Statement 3

  • Statement 4

  • Statement 5

Explicación

Pregunta 4 de 10

1

Airplane c = new Airplane();
Flier f = new Airplane();
Athlete a = new SkiJumper("Ann", "Smith");
SkiJumper s = new SkiJumper("John", "Doe");

Which of the following statements is not legal?

Selecciona una de las siguientes respuestas posibles:

  • c.fly();

  • f.fly();

  • a.train(3);

  • s.train(3);

  • a.fly();

Explicación

Pregunta 5 de 10

1

Airplane c = new Airplane();
Flier f = new Airplane();
Athlete a = new SkiJumper("Ann", "Smith");
SkiJumper s = new SkiJumper("John", "Doe");

Which of the following statements needs a cast?
I. f = c;
II. a = s;
III. s = a;

Selecciona una de las siguientes respuestas posibles:

  • I only

  • II only

  • III only

  • I and II only

  • I and III only

Explicación

Pregunta 6 de 10

1

Suppose class C implements an interface I by implementing all of the methods of I and no further methods. Then which of the following must be true?

Selecciona una de las siguientes respuestas posibles:

  • All instance variables or C are public.

  • All methods of C are abstract.

  • All methods of C are public.

  • All constants of C are public.

  • All instance variables of C are private.

Explicación

Pregunta 7 de 10

1

Which of the following statements is true about casting?

Selecciona una de las siguientes respuestas posibles:

  • You must cast to convert from an interface type to a class type.

  • You must cast to convert from a class type to an interface type.

  • You cannot cast to convert an interface type to a class type.

  • You cannot cast from a class type to an interface type.

  • Both a and b above are true.

Explicación

Pregunta 8 de 10

1

Which of the following statements is true about dynamic binding?

Selecciona una de las siguientes respuestas posibles:

  • Dynamic binding occurs during compile time.

  • Dynamic binding occurs when the appropriate overloaded method is selected.

  • Dynamic binding is another name for early binding.

  • In dynamic binding, the virtual machine selects the appropriate method.

  • Dynamic binding occurs only when an interface declares public static final constants.

Explicación

Pregunta 9 de 10

1

Which of the following statements about interfaces is not true?

Selecciona una de las siguientes respuestas posibles:

  • An interface can specify constants that can be used by all classes that implement the interface.

  • An interface can specify variables that can be used by all classes that implement the interface.

  • An interface can specify methods that must be defined by all classes that implement the interface.

  • An interface name cannot be instantiated.

  • The interface contains declarations but not implementations.

Explicación

Pregunta 10 de 10

1

Suppose foo is an object of class C, and C implements the interface type I. Which of the following statements must be true?

Selecciona una de las siguientes respuestas posibles:

  • foo was constructed with the constructor of I.

  • C assigns values to all constants declared in the interface I.

  • C supplies an implementation for all methods of the interface I.

  • foo must be declared as
    I foo = new C();

  • All methods of I are declared as private.

Explicación