Lecture 12 - 02/13
Midterm 1 Tips/Tricks:
- “Static” keyword: decided at compile time
public static void jump()
- The compiler knows exactly what method is going to get called at compile time.
- You can’t override static.
- If we have a method that is in both
Dog, and they are static, and they have the same signature, what happens?
- Out of scope of class but it uses the static type (compile-time type) of the object.
- Casting only affects static type at compile time (no effect on runtime; possibility that doing an illegal cast which will give runtime error)
- Runtime errors:
- Null pointer exception
- Casting exception
- Overflows in Java: 92834832 * 2349872342 -- “rolls over”
- OutOfMemory error
- If two function headers are same but have different return type, compiler error
- Access modifiers (
private, ...) must line up
- Can't instantiate private helper classes in static methods
- No private methods in interfaces
- Overriding vs. overloading:
- Overloading: Same class, same function name, different parameters
- Overriding: Two classes (one is lower in the inheritance hierarchy than the other), same function name, same parameters