首页 > 代码库 > java基本类型作为成员变量时的初始值
java基本类型作为成员变量时的初始值
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;}
输出:
java基本类型作为成员变量时的初始值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。