我在命令提示符下编译下面的java程序,但它显示错误,我无法修复它

时间:2013-11-10 14:29:27

标签: java

我正在编译cmd中的所有java程序但是当我在程序下运行时,它显示的错误如"reached end of file while parsing"!当我尝试在eclipse中运行它时,它会在粗体代码下面显示红色下划线,这些代码是方法和主要方法。

import java.io.*;

class empl{

    int empno;
    String name;
    String position;
    int ph;

    public void getdata()throws IOException{

        DataInputStream e = new DataInputStream(System.in);

        System.out.println("Enter name: ");
        empno = Integer.parseInt(e.readLine());

        System.out.println("Enter your name: ");
        name = e.readLine();

        System.out.println("Enter the employee position: ");
        position=e.readLine();

        System.out.println("Enter the phone number: ");
        ph = Integer.parseInt(e.readLine());

    }

    public void displaydata() {

        System.out.println(empno+"\t"+name+"\t"+position+"\t"+ph);
    }

class manager extends empl{

    int salary;
    String secname;

    public void getdata() throws IOException{
        getdata();

        DataInputStream e= new DataInputStream(System.in);

        System.out.println("Enter salary: ");
        salary=Integer.parseInt(e.readLine());

        System.out.println("Enter second name: ");
        secname= e.readLine();

    }

    public void displaydata(){
        displaydata();
        System.out.println(salary+"\t"+secname);
    }

class inheritt{
    public static void **main(String []args)throws IOException**{

    inheritt e1= new inheritt();         
    inheritt e2= new inheritt();

  **e1.getdata();
    e2.getdata();

    e1.displaydata();
    e2.displaydata();**

}

2 个答案:

答案 0 :(得分:0)

只有顶级课程可以使用static方法:将inheritt声明为顶级课程而不是内部课程

public class inheritt {
   public static void main(String[] args) throws IOException {
    ...
   }
}

答案 1 :(得分:0)

**e1.getdata();
e2.getdata();

e1.displaydata();
e2.displaydata();**

e1e2属于inheritt type且没有getdata()displaydata()方法

试试这段代码......我想这可能就是你想要的。我修了一些括号,不确定到底在哪里。我也做了inheritt extends manager。我想这就是你想要的。您可能希望显示类的继承链。

import java.io.*;

class empl{

    int empno;
    String name;
    String position;
    int ph;

    public void getdata()throws IOException{

        DataInputStream e = new DataInputStream(System.in);

        System.out.println("Enter name: ");
        empno = Integer.parseInt(e.readLine());

        System.out.println("Enter your name: ");
        name = e.readLine();

        System.out.println("Enter the employee position: ");
        position=e.readLine();

        System.out.println("Enter the phone number: ");
        ph = Integer.parseInt(e.readLine());

    }

    public void displaydata() {
        System.out.println(empno+"\t"+name+"\t"+position+"\t"+ph);
    }
}

class manager extends empl{

    int salary;
    String secname;

     public void getdata() throws IOException{
         getdata();

         DataInputStream e= new DataInputStream(System.in);

         System.out.println("Enter salary: ");
         salary=Integer.parseInt(e.readLine());

         System.out.println("Enter second name: ");
         secname= e.readLine();
    }

    public void displaydata(){
        super.displaydata();
        System.out.println(salary+"\t"+secname);
    }

class inheritt extends manager {
    public static void **main(String []args)throws IOException**{

    inheritt e1= new inheritt();         
    inheritt e2= new inheritt();

    e1.getdata();
    e2.getdata();

    e1.displaydata();
    e2.displaydata();

}