iterator() method API

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
hsiaok
Posts: 7
Joined: Tue Aug 22, 2017 11:13 am
Contact:

iterator() method API

Post by hsiaok »

iterator() is listed as both instance method and abstract method of interface Iterable, like this:

Iterator<T> iterator()
Returns an iterator over elements of type T.
Returns:an Iterator


Under Abstract Method and Instance Method.

I thought an interface has 3 type of methods: default method, static method and abstract method; so my question is why is iterator() is a instance method under Iterable API ?

admin
Site Admin
Posts: 10398
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: iterator() method API

Post by admin »

Not really sure what you mean. iterator() is indeed an abstract method in Iterable interface. See this: https://docs.oracle.com/javase/8/docs/a ... iterator--

If any non-abstract class (for example, ArrayList) says it implements Iterable, then it must provide an implementation of this method. In that case, it will be an instance method of that class.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests