首页 > 其他 > 详细

第5章 面向对象(基础篇)

时间:2016-03-02 23:43:43      阅读:348      评论:0      收藏:0      [点我收藏+]

   1、

class Address {
    private String country;
    private String province;
    private String city;
    private String street;
    private String postcode;
    
    Address() {
        
    }
    
    Address(String country, String province, String city, String street, String postcode) {
        this.country = country;
        this.province = province;
        this.city = city;
        this.street = street;
        this.postcode = postcode;
    }
    
    public void show() {
        System.out.println("地址为:"+country+province+city+street+"    邮编: "+postcode);
    }
}
public class AddressTest {

    public static void main(String[] args) {
        new Address("中国", "湖北省", "天门市", "陆羽大道", "427806").show();
    }

}

   2、

class Employee {
    private String id;
    private String name;
    private double base_salary;
    private double increase_salary;
    
    Employee(String id, String name, double base_salary, double increase_salary) {
        this.id = id;
        this.name = name;
        this.base_salary = base_salary;
        this.increase_salary = increase_salary;
    }
    
    public double getIncrease_salary() {
        return increase_salary;
    }
    
    public double getTotalSalary() {
        return increase_salary + base_salary;
    }
    
}
public class EmployeeDemo {

    public static void main(String[] args) {
        Employee li = new Employee("211016040", "李阿昀", 5000, 2500.50);
        System.out.println("薪水增长额:"+li.getIncrease_salary());
        System.out.println("增长后的工资总额为:"+li.getTotalSalary());
    }

}

   3、

 

第5章 面向对象(基础篇)

原文:http://www.cnblogs.com/yerenyuan/p/5236692.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!