java里面有这么一条: 在静态方法中不可调用非静态变量和非静态方法,但为什么可调用println()方法?(查jdk后知道println()方法不是静态的),是因为println()只可以有System.out.调用的缘故吗??
例:
public class Hello
{
// static int w;
public static int getInt()
{
return 12;
}
public static void main(String[] fdsa)
{
System.out.println("Hello World!");
// w=12;
int s=getInt();
System.out.println(s);
}
}
感谢解答者,麻烦写的详细点。
例:
public class Hello
{
// static int w;
public static int getInt()
{
return 12;
}
public static void main(String[] fdsa)
{
System.out.println("Hello World!");
// w=12;
int s=getInt();
System.out.println(s);
}
}
感谢解答者,麻烦写的详细点。
像你说的通过其他的方法调用。应该也可以 只要你得到一个PrintStream的对象就可以调用Println()了。但是好像生成这个对象有点麻烦 而且要处理很多异常……