静态方法和非静态方法
public class Demo03 {
public static void main(String[] args) {
//静态方法
//Student.say();
//非静态方法
//对象类型 对象名= 对象值
Student student = new Student();
student.say();
}
//static和类一起加载的,一开始就存在
public static void a(){
// b();已经存在的调用不存在的,会报错
}
//和对象有关,对象创建之后才存在,类实例化之后才存在
public void b(){
}
}
//学生类
public class Student {
//属性:字段
String name;//null
int age;//0
//方法
public void say(){
System.out.println(this.name+"在学习");
}
}
浙公网安备 33010602011771号