What types can use "final" modifier?
-
-
instance variable
- Same with "constant value"
-
-
can initialize in:
- static or instance initilization block
- constructor
- Class
- Method
What is specific characteristic of "final" modifier?
-
-
instance variable
- Can't assign value(like class.var)
- NOT IMMUTABLE!
- Use Setter method!
- *in main method, you can initialize final value but can't do re-assign value
- Can't change reference address
-
-
Class
- Can't define child class
-
-
Method
- Can't override method
Summary of mechanism about "System.out.println(obj);"
- System.out.println(obj) calls "String valueOf()" method
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
} - String valueOf() calls "toString()"
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}-
Neccessary to @override!
- toString method will return address!
- toString access modifier is 'public' ! So, child class must use public to override method