文件名称:toString方法示例-Chap6 Java常用类
文件大小:330KB
文件格式:PPT
更新时间:2024-05-16 03:14:41
java常用类
toString方法示例 package chap6; public class Account { private String name; private double balance; public Account(String name, double balance) { this.name = name; this.balance = balance; } public String toString() { return "The account: " + name + "has balance: " + balance; } } 运行结果: 未覆盖toString方法:chap6.Account@c17164 覆盖toString方法后:The account: mary has balance: $100000.0