类与对象初见
package com.bo.test;
public class Student {
//属性:字段
String name;
int age;
//方法
public void study(){
System.out.println(this.name + "a student is studying now");
}
}
package com.bo.test;
//一个项目只能有一个main方法,存在单独一个类中
public class application {
public static void main(String[] args) {
Student student = new Student();
student.name = "Bo";
//new一个对象,字段会初始化为null,并且会调用构造器
System.out.println(student.name);
}
}
- 快捷键 new 回车之后,Alt+enter即可
- 单独一个application类来运行main