构造方法
package com.leiheduixiang.a;
public class Dog {
public String name,kind,sex;
public Dog() {
name="小白";
kind="二哈";
sex="女";
System.out.println("执行构造方法");
}
}
package com.leiheduixiang.a;
public class Test3 {
public static void main(String[] args) {
Dog dog=new Dog();
System.out.println("我的名字是:"+dog.name+",品种是:"+dog.kind+",性别是:"+dog.sex); //
}
}
final
package com.leiheduixiang.a;
public class xunlian {
public static final String SEX="男"; //
public String name,kind,sex;
public xunlian() {
name="小黑";
kind="藏獒";
sex="男";
System.out.println("执行构造方法");
}
}
package com.leiheduixiang.a;
public class Test4 {
public static void main(String[] args) {
xunlian xl=new xunlian();
xl.sex=xunlian.SEX;
System.out.println("狗的名字是:"+xl.name+",品种是:"+xl.kind+",性别是:"+xl.sex);
}
}