Exam 11: Advanced Inheritance Concepts

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

public interface FindTheError {     void firstMethod(int anIntNum)    {         System.out.println("Did you find the error?");    } } What is the problem with the above interface? How would you correct the interface?

Free
(Essay)
4.7/5
(36)
Correct Answer:
Verified

The interface has a method implementation in it. Interface methods cannot contain method bodies. It should have a declaration only.

public interface FindTheError
{
    void firstMethod(int anIntNum);
}

   An array can be created to reserve space for references to objects. Using the code above, explain how an array of superclass references can hold subclass references. An array can be created to reserve space for references to objects. Using the code above, explain how an array of superclass references can hold subclass references.

Free
(Essay)
4.8/5
(32)
Correct Answer:
Verified

The Animal[] animalRef = new Animal[3]; statement reserves enough computer memory for three Animal objects named animalRef[0] , animalRef[1] , and animalRef[2] . The statement does not actually instantiate Animals ; Animal is an abstract class and cannot be instantiated. The Animal array declaration simply reserves memory for three object references. If you instantiate objects from Animal subclasses, you can place references to those objects in the Animal array. The array of three references is used to access each appropriate speak() method.
In the AnimalArrayDemo application, a reference to an instance of the Dog class is assigned to the first Animal reference, and then references to Cow and Snake objects are assigned to the second and third array elements. After the object references are in the array, you can manipulate them like any other array elements. The application uses a for loop and a subscript to get each individual reference to speak() .

What is dynamic method binding and why is it used?

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

An application's ability to  select the correct subclass method depending on the argument type is known as dynamic  method binding. When the application executes, the correct method is attached (or bound) to  the application based on the current, changing (dynamic) context. Dynamic method binding  is also called late method binding. The opposite of dynamic method binding is static (fixed)  method binding. In Java, instance methods (those that receive a this reference) use dynamic  binding; class methods use static method binding. Dynamic binding makes programs flexible;  however, static binding operates more quickly.

A class that will be placed in a nondefault package for others to use must be private .

(True/False)
4.9/5
(33)

What is the toString() method used for and how is it used?

(Essay)
4.8/5
(38)

When a superclass is abstract, you cannot instantiate objects of a superclass. How can you use a superclass abstract object?

(Essay)
4.8/5
(41)

When you create a useful, extendable superclass, you and other future programmers gain what advantages?

(Essay)
4.8/5
(41)

The capability to inherit from more than one class is called ____.

(Multiple Choice)
4.7/5
(41)

A(n) ____ looks much like a class, except that all of its methods (if any) are implicitly public and abstract.

(Multiple Choice)
4.9/5
(43)
Match each term with the correct statement below.
Data fields in an interface
interface
A class-naming conflict
nonabstract method
A method that is inherited
dynamic method binding
Correct Answer:
Verified
Premises:
Responses:
Data fields in an interface
interface
A class-naming conflict
nonabstract method
A method that is inherited
dynamic method binding
An alternative to multiple inheritance available in Java
virtual classes
Considers two objects of the same class to be equal only if they have the same hash code
equals() method
The correct subclass method is attached to the application
java.lang
Prohibited in Java
multiple inheritance
Contains the Object class
collision
The name given to abstract classes in other programming languages, such as C++
public , static , and final
(Matching)
4.7/5
(38)

A(n) ____ is not an object, but it points to a memory address.

(Multiple Choice)
4.8/5
(38)

If Java did not allow you to ____ classes, you would need to create every part of a program from scratch.

(Multiple Choice)
4.8/5
(41)

Classes from which objects can be instantiated are called constant classes.

(True/False)
5.0/5
(35)

Compare and contrast abstract classes and interfaces.

(Essay)
4.8/5
(44)

When you define a class, if you do not explicitly extend another class, your class is an extension of the ____ class.

(Multiple Choice)
4.8/5
(35)

When you create a class and use the implements clause to implement an interface but fail to code one of the interface's methods, the compiler error generated indicates that you must declare your class to be ____.

(Multiple Choice)
4.9/5
(45)

Why do many programmers consider multiple inheritance to be a difficult concept?

(Essay)
4.9/5
(32)

When you create classes for others to use, why would you not want to provide the users with your source code in the files with .java extensions?

(Essay)
4.8/5
(35)

When you create a class that uses an interface, you include the keyword extends .

(True/False)
4.8/5
(43)

When you show abstract classes and methods in class diagrams, their names appear in ____.

(Multiple Choice)
5.0/5
(35)
Showing 1 - 20 of 66
close modal

Filters

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