看板 java 關於我們 聯絡資訊
如題,toString 會傳回物件的字串表示法,意即將物件轉成字串 下面有個小程式 public class Employee { String name; int age; public static void main(String args[]) { Employee tom =new Employee(); System.out.println(tom); System.out.println(tom.toString()); } } 下面兩行印出的結果都是一樣的,不過為什麼toString()可加可不加呢? 可能對大家來說是理所當然的事 不過還是希望能聽聽各位的解說,非常謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.229.200.72 ※ 編輯: seekyou 來自: 220.229.200.72 (04/24 13:57)