JAVA---方法的声明

package lll;


public class Test {
	public static void main(String[] args) {
		Test a=new Test();
		a.method();
		
	}
	public void method(){
		for(int i=0;i<10;i++){
			for(int j=0;j<8;j++){
				System.out.print("* ");
			}
			System.out.println();
		}
	}
}

在main函数外写的方法是不能直接调用的,但是实例化这个方法所在的类,然后用这个对象就可以调用这个方法了。

posted @ 2022-01-06 16:20  ice--cream  阅读(77)  评论(0编辑  收藏  举报