-4

我正在 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();**

}
4

2 回答 2

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

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

e1and e2are of inheritt typeand don't have getdata()anddisplaydata()方法

试试这个代码......我想这可能是你想要的。我固定了一些括号,不太确定去哪里了。我也,做了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();

}
于 2013-11-10T14:46:09.507 回答
0

只有顶级类可以有static方法:声明inheritt为顶级类而不是内部类

public class inheritt {
   public static void main(String[] args) throws IOException {
    ...
   }
}
于 2013-11-10T14:33:52.067 回答