Exam 9: Polymorphism

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

Are there any differences between extending a class and implementing an interface?

Free
(Short Answer)
4.8/5
(37)
Correct Answer:
Verified

Yes. First, extending a class uses the extends keyword, while implementing an interface uses the implements keyword. More importantly, a class can implement multiple interfaces, while it can only extend a single class.

Consider the following line of code. Comparable s = new String(); Which of the following statements is true about this line?

Free
(Multiple Choice)
4.7/5
(32)
Correct Answer:
Verified

C

In Java, a(n) ___________________ is a collection of constants and abstract methods.

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

D

Consider a reference declared in the following manner. Animal a; This reference may only point to an object that created by instantiating the Animal class.

(True/False)
4.9/5
(39)

Give an example of a class that implements the Comparable interface, and explain how the implementation of the compareTo method determines its return value.

(Essay)
4.8/5
(45)

In Java, polymorphic method binding occurs ____________________ .

(Multiple Choice)
4.8/5
(33)

Suppose Animal is an interface that specifies a single method - speak. Now suppose the Dog class implements the Animal interface. In addition to the speak method, the Dog class also has a method called wagTail. Now consider the following code. Animal a = new Dog(); A=wagTail(); Which of the following is true about this code?

(Multiple Choice)
4.7/5
(38)

The compareTo method of the Comparable interface returns a boolean value.

(True/False)
4.7/5
(29)

The next method of the Iterator interface returns a reference to the next element in a collection and removes it.

(True/False)
5.0/5
(32)

Suppose that Horse is a subclass of Animal, and neither class is abstract. Which of the following is an invalid declaration and initialization?

(Multiple Choice)
4.9/5
(43)

Write an interface for a CD player. It should have the standard operations (i.e. play, stop, etc) that usual CD players have.

(Essay)
4.9/5
(36)

Consider a class hierarchy that includes a class called Vehicle, with subclasses called Car and Airplane. The Vehicle class has a method called getMaxSpeed, which is overridden in the Car class. The getMaxSpeed of the Vehicle class returns 760 mph, while the getMaxSpeed method of the Car class is overridden to return 150 mph. What is the output of the following snippet of code? Explain your answer. Vehicle v = new Car(); System.out.println(v.getMaxSpeed() + " mph");

(Essay)
4.8/5
(36)

Describe the compareTo method the circumstances under which it returns different values.

(Essay)
4.9/5
(38)

Which of the following methods are included with any object that implements the Iterator interface?

(Multiple Choice)
4.8/5
(30)

In order to create a class that implements an interface, the __________________ keyword is used.

(Multiple Choice)
4.7/5
(35)

Late binding is _______________ than _______________ .

(Multiple Choice)
4.9/5
(35)

An interface cannot declare any instance variables.

(True/False)
4.9/5
(24)

Consider the following inheritance hierarchy that is used in a video game. Consider the following inheritance hierarchy that is used in a video game.   Which of the following declarations and initializations will not cause a compiler error? Character c = new FlyingDragon(); FlyingDragon f = new Character(); Dragon d = new Villain(); Villain v = new Skeleton(); Dragon d = new ShopKeeper(); Which of the following declarations and initializations will not cause a compiler error? Character c = new FlyingDragon(); FlyingDragon f = new Character(); Dragon d = new Villain(); Villain v = new Skeleton(); Dragon d = new ShopKeeper();

(Essay)
4.9/5
(42)

The commitment to execute certain code to carry out a method invocation is referred to as _________________.

(Multiple Choice)
4.7/5
(48)

Which GUI concepts use polymorphism to establish their relationship?

(Multiple Choice)
4.8/5
(40)
Showing 1 - 20 of 39
close modal

Filters

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