Java在定义一个类的时候里面只能放方法和属性,这是规定死了的。System.out.println()是在调用一个叫println的函数,这里是函数的调用而不是类里面定义一个函数。
还有一种方法可以使得System.out.println()在类内而不是方法中被调用:
class Test{
public static void main(String[] args){
}
static{System.out.println("Hello world");}//static 声明的静态域在类被加载的时候会被调用而不需要创建实例对象。它这时候就不在任何一个方法中。
}
System.out.println()//是输出语句只能在方法中实现,除非在static块中;
were a few women present