码迷,mamicode.com
首页 > 编程语言 > 详细

java基本类型作为成员变量时的初始值

时间:2014-09-16 14:14:10      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   java   ar   2014   div   

 

package primitivetypedefaultvalue;

public class ListDefaultValue {

    public static void main(String[] args) {
        PrimitiveType pt=new PrimitiveType();
        System.out.println(pt.toString());
    }

}
class PrimitiveType{

    @Override
    public String toString() {
        StringBuilder pt=new StringBuilder();
        pt.append("age(int):")
        .append(this.getAge())
        .append("\n")
        .append("moneyL:")
        .append(this.getMoneyL())
        .append("\n")
        .append("moneyF:")
        .append(this.getMoneyF())
        .append("\n")
        .append("moneyD:")
        .append(this.getMoneyD())
        .append("\n")
        .append("sex (char):")
        .append(this.getSex())
        .append("; ")
        .append("length(original):")
        .append(String.valueOf(this.getSex()).length())
        .append("; ")
        .append("length(after trim()):")
        .append(String.valueOf(this.getSex()).trim().length())
        .append("\n")
        .append("retire(boolean):")
        .append(this.isRetire())
        .append("\n")
        
        ;
        return pt.toString();
    }
    
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public long getMoneyL() {
        return moneyL;
    }
    public void setMoneyL(long moneyL) {
        this.moneyL = moneyL;
    }
    public float getMoneyF() {
        return moneyF;
    }
    public void setMoneyF(float moneyF) {
        this.moneyF = moneyF;
    }
    public double getMoneyD() {
        return moneyD;
    }
    public void setMoneyD(double moneyD) {
        this.moneyD = moneyD;
    }
    public char getSex() {
        return sex;
    }
    public void setSex(char sex) {
        this.sex = sex;
    }
    public boolean isRetire() {
        return retire;
    }
    public void setRetire(boolean retire) {
        this.retire = retire;
    }

    private int age;
    private long moneyL;
    private float moneyF;
    private double moneyD;
    private char sex;
    private boolean retire;
}

 

输出:
bubuko.com,布布扣

 

java基本类型作为成员变量时的初始值

标签:style   blog   http   color   os   java   ar   2014   div   

原文地址:http://www.cnblogs.com/softidea/p/3974744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!