【发布时间】:2015-09-10 19:49:40
【问题描述】:
下面会在public static void DemoMethod() 中引发错误。为什么?
package demoblock;
/**
*
* @author coleen
*/
public class DemoBlock {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Demontrating block scope");
int x = 1111;
System.out.print("in first block x is" + x);
{
int y = 2222;
System.out.println(" In second block x is " + x);
System.out.println(" In seond block y is " + y);
}
{
int y = 3333;
System.out.println(" In third block x is " + x);
System.out.println(" In third block y is " + y);
DemoMethod();
System.out.println(" After method x is " + x);
System.out.println(" After method block y is " + y);
System.out.println(" At the end x is " + x);
public static void DemoMethod()
{
int x = 8888;
int y = 9999;
System.out.println(" In demoMethod x is " + x);
System.out.println(" In DemoMethod block y is " + y);
}
}
【问题讨论】:
-
你不能把一个方法放在另一个方法里面。还要注意,您的括号在提供的代码中是不平衡的。 (最后你至少错过了一个。)