静态和动态方法

package oop;
//静态方法的调用
public class Demon01 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Student.say();
	//Student student = new student();
}
//学生类

public static class Student{//静态方法
public static void say(){
System.out.println("学生说话了");//方法
}
}
}
输出结果:
学生说话了

//非静态方法,实例化这个类new
//对象类型 对象名=对象值;
package oop;
//非静态方法,实例化这个类new
//对象类型 对象名=对象值;
public class Demon01 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Student student=new Student();
	Student.say();
	//Student student = new student();
}
//学生类

public class Student{//非静态方法
public void say(){
System.out.println("学生说话了");//方法
}
}
}
输出答案:
学生说话了

posted @ 2025-03-25 20:11  骆驼刺破仙人掌007  阅读(7)  评论(0)    收藏  举报