本人的在eclipse中写的java程序如下(程序1):
import java.io.*;
public class Nixu 
{
    class Input
    {
        BufferedReader br;
        String s;
        int i;
        int init()
        {
            br=new BufferedReader(new InputStreamReader(System.in));
            try
            {
                s=br.readLine();
            }
            catch(IOException e)
            {
                e.getStackTrace();
            }
            return i=Integer.parseInt(s);
        }
    }
    public static void main(String[] args) 
    {
        //Input p = new Input();
    }
}程序没有错误,但是如果我把类Input 移到公共类的外面 改成如下程序(程序2):import java.io.*;
class Input
    {
        BufferedReader br;
        String s;
        int i;
        int init()
        {
            br=new BufferedReader(new InputStreamReader(System.in));
            try
            {
                s=br.readLine();
            }
            catch(IOException e)
            {
                e.getStackTrace();
            }
            return i=Integer.parseInt(s);
        }
    }
public class Nixu 
{
    
    public static void main(String[] args) 
    {
        //Input p = new Input();
    }
}程序就出错了 错误在第一行 import java.io.*; 错误提示是 Mutiple ers at this line, the type Input is already defined,30已更改 行。顺便问一下 在程序1中 我把注释行//Input p = new Input();的注释去掉,程序就错了 错误提示是:
No enclosing instance of type Nixu is accessible. Must qualify the allocation with 
 an enclosing instance of type Nixu (e.g. x.new A() where x is an instance of Nixu). 

这个又是怎么回事啊????

解决方案 »

  1.   

    import java.io.*;class Input {
    BufferedReader br;
    String s;
    int i; int init() {
    br = new BufferedReader(new InputStreamReader(System.in));
    try {
    s = br.readLine();
    } catch (IOException e) {
    e.getStackTrace();
    }
    return i = Integer.parseInt(s);
    }
    }public class Nixu { public static void main(String[] args) {
    Input p = new Input();
    }
    }我的没有错误.. 你是不是在同包下还有其他的 input 之类的. 
      

  2.   


    import java.io.*;
    public class Nixu 
    {
        
        public static void main(String[] args) 
        {
            Input p = new Input();
    p.init();
        }
    }class Input
        {
            BufferedReader br;
            String s;
            int i;
            int init()
            {
                br=new BufferedReader(new InputStreamReader(System.in));
                try
                {
                    s=br.readLine();
                }
                catch(IOException e)
                {
                    e.getStackTrace();
                }
                return i=Integer.parseInt(s);
            }
        }你是不是要写成这个样子啊。就是在控制台上输入数字,你就返回数字!
      

  3.   

    程序1是内部类,在内部类外访问需要通过外部类    ...
        public Input getInput()  //增加一方法
        {
         return new Input();
        }
        
        public static void main(String[] args) 
        {
         Test t = new Test();
         Test.Input p = t.getInput(); //通过外部类名及类引用
        }
    程序2没错,肯定是其他问题
      

  4.   

    LZ你的程序1是个内部类,创建非静态内部类对象时,一定要先创建起相应的外部类对象.
    你这样试下:Nixu ni=new Nixu(); //创建外部内对象ni
               Nixu.Input input=ni.new Input(); //利用外部类创建内部类对象input
    建议LZ看下内部类方面的书