类与对象的创建

类与对象的创建

public class application {
    public static void main(String[] args) {
        student xm = new student();
        student xy = new student();
        xm.name ="xiaoming";
        xm.age = 11;
        System.out.println(xm.name);
        System.out.println(xm.age);
        xm.study(xm);
        System.out.println(xy.name);
        System.out.println(xy.age);
        xy.study(xy);
    }
}

//学生类
public class student {
    String name;
    int age;
    public void study(student s1){
        System.out.println(s1.name + "正在学习");
    }
}
posted @ 2023-12-25 16:29  chengh0618  阅读(4)  评论(0编辑  收藏  举报