Exam 11: Advanced Inheritance Concepts
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?
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.

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?
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 .
When a superclass is abstract, you cannot instantiate objects of a superclass. How can you use a superclass abstract object?
When you create a useful, extendable superclass, you and other future programmers gain what advantages?
The capability to inherit from more than one class is called ____.
A(n) ____ looks much like a class, except that all of its methods (if any) are implicitly public and abstract.
A(n) ____ is not an object, but it points to a memory address.
If Java did not allow you to ____ classes, you would need to create every part of a program from scratch.
Classes from which objects can be instantiated are called constant classes.
When you define a class, if you do not explicitly extend another class, your class is an extension of the ____ class.
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 ____.
Why do many programmers consider multiple inheritance to be a difficult concept?
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?
When you create a class that uses an interface, you include the keyword extends .
When you show abstract classes and methods in class diagrams, their names appear in ____.
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)