From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Discovering inheritance in foundational Java classes

Discovering inheritance in foundational Java classes - Java Tutorial

From the course: Java Object-Oriented Programming

Discovering inheritance in foundational Java classes

- [Instructor] With a good foundation of inheritance, we can begin to explore how the Java programming language uses inheritance. Exploring more examples will help you better understand this object-oriented concept and recognize the scenarios it should be used in. One common Java class is the Stack class. Stack is the data structure and while we won't be exploring data structures too much in this course, we'll explore how this class uses inheritance to inherit behaviors and attributes from its superclass. Here we have a stack of characters and we've added a few characters to the stack with the push method. Then we've removed the characters with the pop method. When the characters are removed, they'll be removed in reverse order, meaning t will be removed, then a, then c. Running the code, we'll see cat displayed in reverse order. That's what makes this a stack. We can plop things on top and remove them in order of…

Contents