JAVA-构造方法

image

package com.itheima02;

public class Student {
    private String name;
    private int age;
    //构造方法
    public Student(){
        System.out.println("无参构造方法");
    }

    public void show(){
        System.out.println(name+","+age);

    }

}

代码2

package com.itheima02;

public class StudentDemo {
    public static void main(String[] args) {
        Student s1=new Student();
        s1.show();

    }
}

执行结果

无参构造方法
null,0

Process finished with exit code 0

posted @ 2022-11-13 16:17  NiceTwocu  阅读(11)  评论(0编辑  收藏  举报