类与对象的创建
package com.zishi.oop.demo02;
public class Student {
//属性:字段
String name;
int age;
//方法
public void study(){
System.out.println(this.name+"在学习");
}
}
package com.zishi.oop.demo02;
//一个项目应该只存在一个main方法
public class Application {
public static void main(String[] args) {
//类:抽象的,实例化
//类实例化后会返回一个自己的对象
//student对象就是一个Student类的具体实例
Student xiaoming = new Student();
Student xiaohon = new Student();
xiaoming.name = "小明";
xiaoming.age = 21;
System.out.println(xiaoming.name);
System.out.println(xiaoming.age);
System.out.println("====================");
xiaohon.name = "小红";
xiaohon.age = 12;
System.out.println(xiaohon.name);
System.out.println(xiaohon.age);
}
}