Netbeans Java 非法 public static void 编译?
Netbeans Java illegal public static void with compiling?
下面在 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);
}
}
/** * * @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 );
}
}
下面在 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);
}
}
/** * * @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 );
}
}