Java Chapter 11 Flashcards
26 Questions
100 Views

Java Chapter 11 Flashcards

Created by
@FairDaffodil

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?

<p>NonPerishable myProduct = new NonPerishable();</p> 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?

<p>You must code statements for the setType() method within both the Permanent and Temporary classes.</p> Signup and view all the answers

When you create a superclass and one or more subclasses, each object of the subclass _________ superclass object.

<p>is a</p> Signup and view all the answers

Which of the following statements is true?

<p>Superclasses can contain abstract methods.</p> 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.

<p>reference</p> Signup and view all the answers

An application's ability to select the correct subclass method to execute is known as _________ method binding.

<p>dynamic</p> Signup and view all the answers

Which statement creates an array of five references to an abstract class named Currency?

<p>Currency[] currencyref = new Currency;</p> Signup and view all the answers

You _________ override the toString() method in any class you create.

<p>can</p> Signup and view all the answers

The Object class equals() method takes _________.

<p>one argument</p> 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 _________.

<p>anotherThing is the same type as thing</p> Signup and view all the answers

The Object class equals() method considers two object references to be equal if they have the same _________.

<p>memory address</p> Signup and view all the answers

Java subclasses have the ability to inherit from _________ parent class(es).

<p>one</p> Signup and view all the answers

The alternative to multiple inheritance in Java is known as a(n) _________.

<p>interface</p> 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.

<p>implements</p> Signup and view all the answers

You can instantiate concrete objects from a(n)

<p>neither a nor b</p> Signup and view all the answers

In Java, a class can _________.

<p>inherit from one abstract superclass at most</p> 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) _________.

<p>abstract class</p> Signup and view all the answers

A _____ class is one from which you cannot create any concrete objects, but from which you can inherit.

<p>abstract</p> Signup and view all the answers

An abstract method has a body.

<p>False</p> Signup and view all the answers

You can indirectly create a reference to a superclass abstract object.

<p>True</p> Signup and view all the answers

Only abstract classes can be used to declare class arrays.

<p>False</p> Signup and view all the answers

The Object class is defined in the _____________ package.

<p>java.lang</p> Signup and view all the answers

The Object class_______ method converts an Object into a String...

<p>toString()</p> 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).
  • For the abstract class Product with subclasses Perishable and NonPerishable, legal instantiation is: NonPerishable myProduct = new NonPerishable();
  • For the abstract class Employee, both Permanent and Temporary must implement the setType() 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 the Object 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 the java.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.

Quiz Team

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.

More Quizzes Like This

Use Quizgecko on...
Browser
Browser