返回

java-这段代码给了我一个没有这样的方法错误,为什么会这样,您如何修复它?

发布时间:2022-06-05 15:51:43 244
# 移动端
package com.mbugua.enums;

public class EnumDemo3 {

    public static void main(String[] args) {
       
        //display the price of winesap
        System.out.println("winesap cost " + Apple.Winesap.getPrice() + " cents.\n");
        

        //display all the apples and prices
        System.out.println("All apple prices:");
        for (Apple a : Apple.values()) {
            System.out.println(a + " costs " + a.getPrice() + " cents. ");
        }
        
    }
    
}
enum Apple {
    Jonathan(10), GoldenDel(9), RedDel(12), Winesap(15), Cortland(8);

    private int price;// price of each apple

    //constructor
    private Apple(int price) {
        this.price = price;
    }

    public int getPrice() {
        return price;
    }
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像