(question in green) What does it mean for an inner class object to be a reference of an outer class? what can you use an iterator on but not for each loop on?
Inner class means one class which is a member of another class. Inner classes has access to all members e.g. static and non-static variables and methods, including private of its outer class and may refer to them directly in the same way that other non-static members of the outer class do.
For example
class Outer {
class Inner {
public void display() {
System.out.println("This is inner class method");
}
}
}
public class Main {
public static void main(String[] args) {
new Outer().new Inner().display();
}
}
For Iterator and For each loop
If you want to modify the Collection then use iterator because you can't do it with for each loop
And it will throw a ConcurrentModificationException
If you can modify or delete an item in collection by Iterator
Please let me know if you have any doubt or modify the answer, Thanks :)
(question in green) What does it mean for an inner class object to be a reference...