Java Object类(toString 方法),objecttostring
分享于 点击 5123 次 点评:221
Java Object类(toString 方法),objecttostring
//覆写toString()方法
class Book {
private String title;
private double price;
public Book(String title, double price) {
this.title = title;
this.price = price;
}
@Override
public String toString() {
return "书名:《" + this.title + "》价格:" + this.price;
}
}
public class Demo {
public static void main(String[] args) {
Book b = new Book("Java入门", 88.8);
System.out.println(b);
}
}
相关文章
- 暂无相关文章
用户点评