Java方法的调用
方法的调用
package com.oop.Demo01;
public class Demo01 {
public static void main(String[] args) {
//静态方法的调用
Student.say();
//非静态方法的调用 实例化这个类 new
new Student().hi();//不推荐
//对象类型 对象名 = 对象值;
Student student = new Student();
student.hi();
}
//public static 与类一起加载
public static void a(){
b();//此时无法调用b
}
//public 对象创建以后才存在(类实例化以后)
public void b(){
}
}
调用的Student类:
package com.oop.Demo01;
public class Student {
//静态方法
public static void say() {
System.out.println("静态方法");
}
//非静态方法
public void hi(){
System.out.println("非静态方法");
}
}

浙公网安备 33010602011771号