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