Chapter 8 How to work with inheritance Murach's Java Programming

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Base class, parent class, or super class

A class that another class inherits.

Derived class, child class, or subclass

A class that inherits from an existing class.

Override

A method from the superclass can be overriden with a version of its own method.

Abstract Method

A method that is specified but not implemented in an abstract class. The subclasses must implement this method. To code an abstract method, you code the abstract keyword in the method declaration and you omit the method body.

Final Class

If a class is declared "final" then the class cannot be inherited to the subclass. To prevent a class from being inherited, you can create a final class by coding the final keyword in the class declaration.

Final method

If a method is declared "final" then the method cannot override that method. to prevent subclasses from overriding a method of a superclass, you can create a final method by coding the final keyword in the method declaration. In addition, all methods in a final class are automatically final methods.

Object Class

The Object class in the java.lang package is the superclass for all classes. Every class inherits the Object class or some other class that ultimately inherits the Object Class. The methods defined in the Object class are available to all classes.

final parameter

To prevent a method from assigning a new value to a parameter. To prevent a method from assigning a new value to a parameter, you can code the final keyword in the parameter declaration to create a final parameter. Then, if a statement in the method tries to assign a new value to the parameter, the compiler reports an error.

extends

a subclass can extend the superclass by adding new fields and methods to the superclass

Protected members

are accessible to the current class, to other classes in the same package, and to subclasses.

Abstract Class

is a class that can be inherited by other classes but that you can't use to create an object. To declare an abstract class, code the abstract keyword in the class declaration. An abstract Class can contain fields, constructors, and methods just like other superclasses. When a sublclass inherits an abstract class, all abstract methods in the abstract class must be overridden in the subclass. Otherwise, the subclass must also be abstract. An abstract class doesn't have to contain abstract methods. However, any class that contains an abstract method must be declared as abstract.

Polymorphism

is a feature of inheritance that lets you treat objects of different subclasses that are derived from the same superclass as if they had the type of the superclass. If, for example, Book is a subclass of Product, you can treat a Book object as if it were a Project object.

Annotation

is a standard way to provide information about your code. When you override a method, you can add the @Override annotation to the method.

Inheritance

lets you create a new class based on an existing class. Then the new class inherits the fields and methods of the existing class.

Access modifiers

specify the accessibility of the members declared by a class


Ensembles d'études connexes

Organizations and Markets Final Exam

View Set

Unit 2: Prenatal and Neonatal Part 1

View Set

MGMT 320 Chapter 5,6,9 Assessments

View Set

CON 305 Quiz #9, CON 305 Quiz #1

View Set

psych chapter 15Kyle is extremely manipulative and can look anyone in the eye and lie convincingly. His deceit often endangers the safety and well-being of those around him, but he is indifferent to any suffering they might experience as a result of his a

View Set