(1) null and static ==================== class A { public void f1() { System.out.println("Hello"); } } public class Main { public static void main(String[] args) { A a = null; a.f1(); } } /* (Question 1) Any compilation warning? (Question 2) Can run? Execution error? (Question 3) What if static is applied to f1()? Compilation warning? Execution error? --------- Given wording: The variable a can only be null at this location Can start running Stop with run-time error: NullPointerException Should call in a static way */ (2) tostring(), toString(), @Override ================================================ class Employee { private String id; private String name; private double salary; public Employee(String i, String n, double s) { id=i; name = n; salary = s; } // We will choose one from (A) - (D): //(A) //public String toString() {return id + " " + name + " " + salary;} //(B) //public String tostring() {return id + " " + name + " " + salary;} //(C) //@Override //public String toString() {return id + " " + name + " " + salary;} //(D) //@Override //public String tostring() {return id + " " + name + " " + salary;} } public class Main { public static void main(String[] args) { Employee e = new Employee("002", "Jim", 10); System.out.println(e); //Expected: 002 Jim 10.0 } }