package oop;
public class Student01 {
/*
类与对象的创建
1 先创建一个类不需要main方法
2 定义一个属性和类型
String name;
int age;
3 写一个方法this代表这个类
public void study(){
System.out.println(this.name+"在学习");
4 写一个大类 需要有main方法在main方法里面进行对像的创建
5 通过new Student01 xiaoliu= new Student01();
类名加名字(名字自己定义)来new一个Student01();
给类中的属性和类型赋值
xiaoliu.name="小刘";
xiaoliu.age=3;
最后进行输出 System.out.println(xiaoliu.name);
System.out.println(xiaoliu.age);
*/
// 属性:字段
String name;
int age;
//方法
public void study(){
System.out.println(this.name+"在学习");
}
}
// 一个项目应该自有一个main方法
public class Application {
public static void main(String[] args) {
//类是抽象的需要实例化
//类实例化后会返回一个自己的对象!
// Student01对象就是一个 Student01类的具体实例
Student01 xiaoliu= new Student01();
Student01 aho= new Student01();
xiaoliu.name=“小红”;
xiaoliu.age=3;
System.out.println(xiaoliu.name);
System.out.println(xiaoliu.age);
aho.name=“小红”;
aho.age=3;
System.out.println(aho.name);
System.out.println(aho.age);
}
}