From the course: Java: Generic Classes

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Generic class hierarchies

Generic class hierarchies - Java Tutorial

From the course: Java: Generic Classes

Generic class hierarchies

- [Instructor] Let us now understand generic class hierarchies but before that, let's do a quick recap of Java inheritance. When you implement inheritance with Java, you can always assign an object of the child class to a reference variable of the parent class. So let's say you have a class called Animal. This is the super class, and you're going to have a Dog, class which is derived out of Animal. So Dog is the sub-class. When you have this kind of a relationship, you can write a line of code like this, Animal animal = new Dog, which means you have an object of the dog, which is the sub-class, and you can refer to it by a variable of the type Animal, which is the superclass. Additionally, in inheritance with Java, you can always pass child class as an argument to a method that accepts the parent class as a parameter. Let's understand this. Let's say you have a class called AnimalUtils and inside that, you have a static…

Contents