eclipse中无法访问的代码

wor*_*ood -1 java eclipse

以下是什么意思?

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unreachable Code    
at mycode.sample.main(sample.java:24) 
Run Code Online (Sandbox Code Playgroud)

我希望我能找到发生错误的那一行。我认为“24”是这一行,但我的项目中只有 23 行代码。

这是项目代码

package mycode;
import java.io.*;

public class sample {
  int first;
  int second;

  public sample (int fir,int sec)
  {
    fir = first;
    sec = second;
  }

  public void add()
  {
    System.out.println(first+second);       
  }

  public static void main(String[] args) throws IOException
  {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int f = Integer.parseInt(reader.readLine());
    // int s =  Integer.parseInt(reader.r   eadLine());
    sample sample2 = new sample(f,100);
    sample2.add();
  } 
}   
Run Code Online (Sandbox Code Playgroud)

我想了解此错误消息。提前致谢。

小智 5

尝试更改您的构造函数,从:

public sample (int fir,int sec)
{
    fir = first;
    sec = second;
}
Run Code Online (Sandbox Code Playgroud)

到:

public sample (int fir,int sec)
{
    first = fir;
    second = sec;
}
Run Code Online (Sandbox Code Playgroud)