非静态方法

Demon01类中:
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();
}

}
学生类:
package oop;

public class Student {
//学生类//非静态方法
public void say(){
System.out.println("学生说话了");//方法
}
}
在Demon01类中调用Student类中的say方法的输出结果:
学生说话了

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