zoukankan      html  css  js  c++  java
  • JAVA基础学习之路(十)this关键字


    class
    Book { String name; int price; int num;
    //构造方法之间的互相调用解决了代码的重复问题,但是一定要留出口
    public Book() { this("请输入书名",0,0); } public Book(String name) { this(name,9999,9999);//this调用方法 } public Book(String name,int num) { this(name,num,9999); } public Book(String name,int num,int price) { this.name = name; //this调用属性 this.price = price; this.num = num; } public String getInfo() { return "书名: "+this.name+" "+ "数目: "+this.num+" " + "单价: " +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("老人与海",5); Book book_3 = new Book("陆炳勋",3,2); System.out.println(book_0.getInfo()); System.out.println(book_1.getInfo()); System.out.println(book_2.getInfo()); System.out.println(book_3.getInfo()); } }
  • 相关阅读:
    hdu 1106 排序(排序)
    hdu 1040 As Easy As A+B(排序)
    hdu 1029 Ignatius and the Princess IV(排序)
    mysql-9索引
    mysql-8 alter命令
    mysql-7事务管理
    mysql-6正则表达式
    http协议
    9-2交互体验
    9-2专项测试下午
  • 原文地址:https://www.cnblogs.com/xhnxhnu/p/9141350.html
Copyright © 2011-2022 走看看