Inheritance and Polymorphism

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

18 Terms

1
New cards

* **Inheritance:

A mechanism where a subclass (child) acquires the fields and methods of a superclass (parent) using the `extends` keyword, letting you reuse code and build an "is-a" relationship.

2
New cards

* **Superclass (Base/Parent Class):

The general, top-level class that shares its common features with subclasses.

3
New cards

* **Subclass (Derived/Child Class):

The specialized class that inherits from a superclass and can add its own unique fields, methods, or overridden behaviors.

4
New cards

* **`extends` keyword:

The Java keyword used in a class declaration to establish the inheritance link between a subclass and its superclass.

5
New cards

* **Constructor Chaining:

When creating a subclass object, Java automatically triggers constructors up the entire inheritance chain (from child all the way to `Object`).

6
New cards

* **`super` keyword:

A keyword used inside a subclass to either invoke a superclass constructor (must be the very first line) or call a superclass method.

7
New cards

* **Method Overriding:

When a subclass provides its own custom implementation of a method already defined in its parent class, keeping the exact same method signature and return type.

8
New cards

* **Method Overloading:

Defining multiple methods with the exact same name but different parameter lists, either inside the same class or across related inheritance classes.

9
New cards

* **Object Class (`java.lang.Object`):

The ultimate root parent of every single class in Java; if a class doesn't specify an extension, it automatically inherits from `Object`.

10
New cards

* **`toString()` method:

A built-in method from the `Object` class that returns a string representation of an object, which should be overridden in your classes to show meaningful data instead of memory addresses.

11
New cards

* **Polymorphism:

The feature where a supertype variable can hold a subtype object (e.g., `Object x = new Student()`), allowing code to handle different object types uniformly.

12
New cards

* **Dynamic Binding:

At runtime, the JVM figures out which overridden method to execute by searching "bottom-up"—starting from the specific subclass and walking up the inheritance tree until it finds the implementation.

13
New cards

* **Generic Programming:

Writing methods with general parameter types (like `Object`) so they can accept and operate on any subclass object.

14
New cards

* **`instanceof` operator:

A safety check used to test whether an object reference actually points to an instance of a specific class before performing operations.

15
New cards

* **Implicit Casting:

Automatically converting a subtype reference into a supertype reference (moving *up* the tree), which is always safe because a child "is a" parent.

16
New cards

* **Explicit Casting:

Manually forcing a supertype reference down to a subclass reference using target parentheses (e.g., `(Student)o`), which is required when moving *down* the tree and can throw errors if mismatched.

17
New cards

* **`protected` modifier:

A visibility level that allows fields and methods to be accessed by any class in the same package or by subclasses anywhere in other packages.

18
New cards

* **`final` modifier:

A restriction tool that locks down code: a `final` class cannot be extended, a `final` method cannot be overridden, and a `final` variable becomes a constant.