JGRASP 告诉我在引用组件或变量时使用 public 或 private 是错误的

JGRASP is telling me using public or private when referencing a component or variable is wrong

 private class RoutinePanel extends JPanel
 {

  public RoutinePanel()
  {

      //labels
    private JLabel messageLabel;

      //constants for Routine Charges

    private final double OIL_CHANGE_CHARGE = 26.0;
    private final double LUBE_JOB_CHARGE = 18.0;
    private final double RADIATOR_FLUSH_CHARGE = 30.0;
    private final double TRANS_FLUSH_CHARGE = 80.0;
    private final double INSPECTION_CHARGE = 15.0;
    private final double MUFFLER_CHARGE = 100.0;
    private final double TIRE_ROTATION_CHARGE = 20.0;

JGRASP 告诉我在这种情况下使用 private 是非法操作。`然而,我的老师特别告诉我们以这种方式创建它。如果需要,我可以提供我们从教授那里收到的伪代码。

我也试过用 public 替换 private。

包含 private

的所有行的错误消息相同

JoesAutomotive.java:57: 错误:表达式的非法开始

  private JLabel messageLabel;

privatepublic 在方法定义中是非法的(在这种情况下,RoutinePanel 的构造函数)

您需要在任何方法定义之外的 class 中声明 class 成员变量。喜欢:

private class RoutinePanel extends JPanel
{

  //labels
  private JLabel messageLabel;

  //constants for Routine Charges
  private final double OIL_CHANGE_CHARGE = 26.0;
  // ...

  public RoutinePanel()
  {