我在命令提示符下编译了下面的java程序,但它';它显示了一个错误,我无法修复它
我正在用cmd编译我所有的java程序,但当我在下面的程序中运行时,它显示了一个错误,如“解析时到达文件末尾”!当我尝试在eclipse中运行它时,它会在粗体代码下面显示红色下划线,这是方法和主要方法我在命令提示符下编译了下面的java程序,但它';它显示了一个错误,我无法修复它,java,Java,我正在用cmd编译我所有的java程序,但当我在下面的程序中运行时,它显示了一个错误,如“解析时到达文件末尾”!当我尝试在eclipse中运行它时,它会在粗体代码下面显示红色下划线,这是方法和主要方法 import java.io.*; class empl{ int empno; String name; String position; int ph; public void getdata()throws IOException{
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();**
}
只有顶级类可以有
static
方法:将inherit
声明为顶级类而不是内部类
public class inheritt {
public static void main(String[] args) throws IOException {
...
}
}
e1
和e2
属于inherit类型
,没有getdata()
和displaydata()
方法
请尝试此代码。。。我想这可能是你想要的。我修复了一些括号,不确定放在哪里。我还制作了inherit扩展管理器
。我想这就是你想要的。您可能希望显示类的继承链
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();
}
你错过了最后一个括号,你得到了什么样的错误?考虑正确地缩进代码示例。(这可能至少会使大括号问题变得明显。)此外,为了突出代码示例中的错误,最好使用注释。因此,不会将代码格式化为粗体,这样星号就不会突出,只会给复制粘贴代码的任何人一点额外的工作来尝试。除了缺少大括号之外,代码中的
***
字符是什么?那真的会给你编译时间吗errors@user2104603看看我的答案,它可能会解决你的问题。
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();
}