.iterator() method on classes which implement Iterable, it should return an Iterator objectIterator object allows us to go through the list..next() - gives you the next element, and advances the iterator, throws an exception if there is no next element..hasNext() - true if there is, false if notex:
ArrayList<String> names = new ArrayList<>();
names.add("John");
names.add("Mary");
names.add("Rose");
Iterator<String> iter = names.iterator();
while(iter.hasNext()){
String value = iter.next();
System.out.println(value);
}
the programmer doesnt have to worry about iterating through the list
public class B extends A{...}super() to call the parent/super class's constructorsuper() constructorsuper to call methods from the base class, such as super.toString()Person p = new Student() but don't do Student p = new Person()
Object type, so we could compare it to any Object.Object parameter is powerful as any class can be input there.@Override tells the compiler that it should expect to be overriding a method from some parent classObject.getClass() is a final method, so we are not allowed to overwrite it for any classFaculty carol = new Faculty("Carol Huffteacher",
"999-99-9999", 1995);
Person p = carol;
System.out.println(carol.toString());
//which toString will be called?
the answer depends on the language you are writing code on, obviously in this class we are dealing with Java
Early (Static) binding - p is type Person, therefore it should call the Person's class toString()
Late (dynamic) binding - p refers to an Object of type Faculty so it should call the toString() of that class.
why do the creators of these languages choose between these two?
java uses late binding by default but it can be changed.
other languages like C++ use early binding (by default), for our example that means the Faculty.toString() is what is called.
ex:
Person[] list = new Person[3];
list[0] = new Person("Col. Mustard", "000-00-0000");
list[1] = new Student("Ms. Scarlet", "111-11-1111", 1998, 3.2);
list[2] = new Faculty("Prof. Plum", "222-22-2222", 1981);
for(int i = 0; i < list.length; i++){
System.out.println(list[i].toString());
}
/*the toString() that gets printed is from that Object's class
*so the student will have their gpa printed out
*/
polymorphism (here) is the idea that the output of the code has many forms as in, it will output different things depending on the input. if it was early binding, you wouldn't print out the gpa or birthyear/admission for Student and Faculty
StudentID class, which only students had, they would have an instance variable for their card.according to the lecture video: when dont know whether or not to choose between composition or inheritance, pick composition because it is "easier to debug".