From the course: Oracle Java Foundations

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Inheritance

Inheritance

(bright music) - [Instructor] Now to make some of this work, one thing we have is the idea of inheritance. Inheritance means that we have different types of objects and they can inherit or gain or reuse data and behavior from a higher level, more general class. Here we have a toy and we might say all toy objects can play. Now what that play means for that toy may not be defined or it might be very simplistic. And then we can extend that toy object with a more specific form of toy called a ball. Ball also, therefore would know how to play automatically because inheritance allows the ball to inherit the play method. Now the designer of the ball class could go in and write different behavior to make the ball bounce or do whatever you know a ball does when we play with it. Then someone else who's implementing the squeaky toy class would of course also inherit the play method. But again, their code for how the play method works would be different than how a ball method works. And same…

Contents