From the course: Java Object-Oriented Programming

Unlock the full course today

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

Exploring how built-in Java classes use polymorphism

Exploring how built-in Java classes use polymorphism - Java Tutorial

From the course: Java Object-Oriented Programming

Exploring how built-in Java classes use polymorphism

- [Instructor] The Java programming language uses both runtime and compile-time polymorphism under the hood, let's take a look at the ArrayList class. The ArrayList class has two methods with the name addAll, but they have different sets of parameters. The first addAll takes in one parameter, a collection. In the implementation, it adds all the elements from that collection to the end of the ArrayList. Scrolling down, we can see that the second addAll takes in two parameters, the index and the collection. We want to add all the elements to the list, but the index allows us to specify a specific location to add them. We could add the items at the beginning of the list, the end of the list, or somewhere in the middle, and we'd specify where, using that index. The first implementation assumes we want to add the collection to the end, but the second implementation gives us a little more control over where we add the items, this…

Contents