Back to Inheritance (NOT REQUIRED)

Lesson PreviewLesson 3 of 7 in this unit

9.3 EXTRA: Overriding Methods

Part of Inheritance (NOT REQUIRED) in AP® Computer Science A. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

When a subclass provides its own version of a method that its superclass already defines, that is method overriding.

A subclass can override a public method from its superclass by writing a method with the exact same method signature (name and parameters). To indicate that you are overriding a method, put @Override before the method in the subclass. While this isn’t necessary, it is important for preventing errors and code clarity. When you call that method on a subclass instance, Java uses the subclass’s version. In the example below, the method speak() is being overridden:

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for AP® Computer Science A.