以下内容会在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);
}
}
答案 0 :(得分:0)
/** * * @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 );
}
}