Final Modifier + System.out.println(obj)

What types can use "final"   modifier?

    • instance variable
    • Same with "constant value"
      1. can initialize in:
      2. static or instance initilization block
      3. constructor
  1. Class
  2. 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);"  

  1. System.out.println(obj) calls "String valueOf()"  method

    public static String valueOf(Object obj) {

    return (obj == null) ? "null" : obj.toString();

    }
  2. 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