0
点赞
收藏
分享

微信扫一扫

构造方法使用

江南北 2022-03-19 阅读 37
java

无参使用

public class me3fj(这里是类名) {
    String xb;
    int  nl;
    //无参调用
    public me3fj(){
        this.年龄=10;
        this.性别="男";
    }
}
public class method3 (这里是类名){
    public static void main(String[] args) {
        //无参调用
        me3fj me = new me3fj();
        System.out.println(me.nl);;
        System.out.println(me.xb);
      
    }
}

有参使用

public class me3fj(这里是类名) {
    String xb;
    int  nl;
    //有参
    public me3fj(String name){
        this.xb="男";
        this.nl=10;

    }
    }
public class method3(这里是类名) {
    public static void main(String[] args) {
        me3fj e3fj= new me3fj("");
        System.out.println(e3fj.xb);
        System.out.println(e3fj.nl);
    }
}
举报

相关推荐

0 条评论