class Book {
String name;
int price;
int num;
//构造方法之间的互相调用解决了代码的重复问题,但是一定要留出口
public Book() {
this("请输入书名",,);
}
public Book(String name) {
this(name,,);//this调用方法
}
public Book(String name,int num) {
this(name,num,);
}
public Book(String name,int num,int price) {
this.name = name; //this调用属性
this.price = price;
this.num = num; }
public String getInfo() {
return "书名: "+this.name+"\n"+
"数目: "+this.num+"\n" +
"单价: " +this.price; }
} public class test1 {
public static void main(String args[]) {
Book book_0 = new Book();
Book book_1 = new Book("我的世界");
Book book_2 = new Book("老人与海",);
Book book_3 = new Book("陆炳勋",,);
System.out.println(book_0.getInfo());
System.out.println(book_1.getInfo());
System.out.println(book_2.getInfo());
System.out.println(book_3.getInfo());
}
}

最新文章

  1. Android—android与js交互以及相互传参
  2. 你必须知道的ASP.NET-----IHttpAsyncHandler实质
  3. 夺命雷公狗ThinkPHP项目之----企业网站7之栏目的修改(主要用模型来验证字段)
  4. Failed to create the java virtual machine完全解决办法
  5. iOS学习之UIView
  6. 第一个自定义HTML网页
  7. FMDB多线程读写问题,使用FMDataBaseQueue操作可以解决同时打开一个链接de读写问题
  8. bzoj1827 [Sdoi2010]星际竞速
  9. HDU 2671 Can't be easier
  10. NSLog (Log信息的输出)
  11. 【MySQL大系】《Mysql集群架构》
  12. PowerDesigner使用方法入门学习
  13. 高级js--(面向对象js,arguments,闭包,自调)
  14. JavaScript Cookies取值
  15. MySQL按中文拼音排序
  16. 【转】linux之cp/scp命令+scp命令详解
  17. CentOS Maven 删除 *.lastUpdated文件
  18. 145.Binary Tree Postorder Traversal---二叉树后序非递归遍历
  19. AC日记——双栈排序 洛谷 P1155
  20. 无向图Tarjan&&求树直径

热门文章

  1. HDU 2096 小明A+B(%的运用)
  2. Linux 常用命令整理
  3. 个人免签即时到账收款接口 bufpay.com 支持多账号收款
  4. #leetcode刷题之路37-解数独
  5. tomcat如何配置俩个版本
  6. PHP的抽象类和抽象方法以及接口总结
  7. animation(动画)设置
  8. 高性能MySQL--innodb中事务的隔离级别与锁的关系
  9. 使用idea上传项目到gitHub
  10. 8-IdentityServer4登录中心