setSize() is under the context of frame, this is not static.
if you call setSize() directly in main(), no context, and thus the static context, is around it.
if you call setSize() directly in main(), no context, and thus the static context, is around it.
| |
| 你说爱我只是习惯 |
| 再也不是喜欢 |
| 我给你的爱 |
| 已不再温暖 |
| |
+--by bookbobby(书呆)-*/
{
System.out.println(msg);
}
public static void main(String[] args)
{
JFrame frame=new JFrame();//这样先new就不是一个静态方法
frame.print("hello");
}
public static void print(String msg)
{
System.out.println(msg);
}
public static void main(String[] args)
{
print("hello");//不new直接调用就必须是一个静态方法
}
通过静态方法中的local-field,可以调用非静态方法
可否举个例子??
static void method1(){}
void method2(){} public static void main(String[] args){
method1();
Test test=new Test(); test.method2();
}
}