类与对象

类是抽象的,通过new来实例化,得到一个对象。
`package jiChuLianXi;

public class Student {
String name;
int age;

//打印年龄和姓名
public void student(){
    System.out.println(this.name);
    System.out.println(this.age);
}

}
/*
public static void main(String[] args) {
Student xm = new Student();
Student xh = new Student();
xm.name="小明";
xh.name="小红";
xm.age=18;
xh.age=25;

    System.out.println(xm.name);
    System.out.println(xm.age);
    System.out.println(xh.name);
    System.out.println(xh.age);
}

*/`

posted on 2022-08-03 21:12  不若地狱  阅读(14)  评论(0编辑  收藏  举报