面向对象①

package com.fan.x;
public class All {
//一个项目应当只有一个main方法
public static void main(String[] args) {
//类(Student):抽象的,需要实例化(用new)
//类实例化之后会返回一个自己的对象
//student对象就是Student类的一个具体实例
Student student = new Student();//对②的Student类进行实例化
}
}

package com.fan.x;

//创建一个Student类

public class Student {
// 属性:字段
String name;
int age;

 


//方法
public void study(){
System.out.println(this.name+"正在学习");
}
}

 

posted @ 2022-01-24 22:31  就不睡觉  阅读(30)  评论(0)    收藏  举报