Questions and Answers
Parent classes are _________ than their child classes.
Less Specific
Abstract classes differ from other classes in that you _________.
cannot instantiate objects from them
Abstract classes can contain _________.
both Abstract and nonabstract methods
An abstract class Product has two subclasses, Perishable and NonPerishable. Which of the following statements is legal?
Signup and view all the answers
An abstract class Employee has two subclasses, Permanent and Temporary. Before you can instantiate these objects, which of the following statements must be true?
Signup and view all the answers
When you create a superclass and one or more subclasses, each object of the subclass _________ superclass object.
Signup and view all the answers
Which of the following statements is true?
Signup and view all the answers
When you create a _________ in Java, you create a variable name in which you can hold the memory address of an object.
Signup and view all the answers
An application's ability to select the correct subclass method to execute is known as _________ method binding.
Signup and view all the answers
Which statement creates an array of five references to an abstract class named Currency?
Signup and view all the answers
You _________ override the toString() method in any class you create.
Signup and view all the answers
The Object class equals() method takes _________.
Signup and view all the answers
Assume the following statement appears in a working Java program: if(thing.equals(anotherThing)) x = 1; You know that _________.
Signup and view all the answers
The Object class equals() method considers two object references to be equal if they have the same _________.
Signup and view all the answers
Java subclasses have the ability to inherit from _________ parent class(es).
Signup and view all the answers
The alternative to multiple inheritance in Java is known as a(n) _________.
Signup and view all the answers
When you create a class that uses an interface, you include the keyword _________ and the interface's name in the class header.
Signup and view all the answers
You can instantiate concrete objects from a(n)
Signup and view all the answers
In Java, a class can _________.
Signup and view all the answers
When you want to provide some data or methods that subclasses can inherit, but you want the subclasses to override some specific methods, you should write a(n) _________.
Signup and view all the answers
A _____ class is one from which you cannot create any concrete objects, but from which you can inherit.
Signup and view all the answers
An abstract method has a body.
Signup and view all the answers
You can indirectly create a reference to a superclass abstract object.
Signup and view all the answers
Only abstract classes can be used to declare class arrays.
Signup and view all the answers
The Object class is defined in the _____________ package.
Signup and view all the answers
The Object class_______ method converts an Object into a String...
Signup and view all the answers
Study Notes
Key Concepts in Java Inheritance and Abstract Classes
- Parent classes are less specific than child classes, creating a general to specific hierarchy.
- Abstract classes cannot be instantiated directly; they act as templates for subclasses.
- Abstract classes can contain both abstract (no implementation) and nonabstract methods (with implementation).
Legal Statements and Constructors
- For the abstract class
Product
with subclassesPerishable
andNonPerishable
, legal instantiation is:NonPerishable myProduct = new NonPerishable();
- For the abstract class
Employee
, bothPermanent
andTemporary
must implement thesetType()
method to be instantiated.
Object Relationships
- Each object of a subclass is considered an instance of the superclass, emphasizing the "is a" relationship.
- Superclasses may contain abstract methods, allowing flexibility for subclasses.
References and Dynamic Binding
- Creating a reference in Java allows holding the memory address of an object.
- Dynamic method binding occurs when an application selects the correct subclass method to execute at runtime.
Array Creation with Abstract Classes
- An array of references to an abstract class can be declared using
Currency[] currencyref = new Currency;
.
Method Overriding and Object Comparison
- Any class can override the
toString()
method, enabling custom string representation. - The
equals()
method in theObject
class requires one argument and considers two object references equal if they share the same memory address.
Inheritance Constraints
- Java supports single inheritance for subclasses, permitting inheritance from one abstract superclass.
- Interfaces serve as the alternative to multiple inheritance in Java, allowing a class to implement multiple interfaces.
Additional Notes on Abstract Classes and Interfaces
- Use the keyword
implements
to define a class that includes an interface. - Neither abstract classes nor interfaces can be instantiated directly.
- Abstract classes are suitable for providing base functionality with the option for subclasses to override specific methods.
General Facts about Java
- The
Object
class is located in thejava.lang
package, providing fundamental methods for all Java objects. - Abstract methods do not have a body, whereas concrete classes can have complete implementations.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of Java's abstract classes and inheritance concepts with these flashcards from Chapter 11. Each card presents key terms and definitions to help reinforce your understanding of parent and child classes. Perfect for students looking to solidify their programming skills.