找不到Inherited类

时间:2017-04-26 13:36:44

标签: java inheritance cannot-find-symbol

我对之前的问题反应非常好,所以我要在这里推得好运。 虽然有一篇很好的帖子已经提到了这一点; What does a "Cannot find symbol" compilation error mean?我正在努力寻找适用的理由和原因。

在创建对象FirstClassTicket时,会出现错误,它在调用FirstClass的equals之前和之后。我假设我从Ticket继承了FirstClass时发生了错误,因为在我开始包含不同的Ticket类型之前,它最初运行良好的调用Ticket。

class Booking{
    public  static   class Ticket{
        int Price;
        int Amount=1;
        int Discount=0;
        public int WhatCost(){
            int Cost =Amount*(Price-Discount);
            return Cost;
        }
        //Inheriting Ticket classes.
    class FirstClass extends Ticket{ //Defines standard class tickets.
        int Price =10;
    }

    }
    public static void main(String args[]) {
      FirstClass FirstClassTicket=new FirstClass(); 
        Scanner scanner = new Scanner(System.in);
        System.out.println("Welcome to the advance booking service.");//Introduce program.
        System.out.println("A first class ticket costs:");
        System.out.println(FirstClassTicket.WhatCost());
    }
}

1 个答案:

答案 0 :(得分:0)

您已将FirstClass定义为故障单的内部类。将FirstClass设为静态并访问它,如下所示。

Booking.Ticket.FirstClass FirstClassTicket=new Booking.Ticket.FirstClass();