Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is List not simply defined as an abstract class rather than being an interface?

We have something like

List lst = new LinkedList();

which shows that List is some sort of Class. So, why call it an Interface? We can simply call it an Abstract class which implements Collection.

like image 661
Nihal Sharma Avatar asked Feb 19 '23 14:02

Nihal Sharma


1 Answers

Interfaces and Abstract classes are used for different purposes. See this question.

A List defines a set of behaviour we want list-type objects to have, not the basis for a hierarchy of data structures. It doesn't need to specify any shared behaviour or anything like that. It just has the simple job of saying "everything that wants to call itself a List should be able to do these things"

like image 100
Oleksi Avatar answered Mar 06 '23 18:03

Oleksi