首页 > 解决方案 > 如何在内部类中使用枚举?

问题描述

我有一个 PhoneContact 类,它是一个内部类,我需要为电话接线员定义一个枚举。当我尝试在 PhoneContact 类中定义它时,出现错误。这样做的正确方法是什么?代码:

public class Contacts {
    class Contact {
        private String date;
        private String type;

        public Contact(String date, String type) {
            LocalDate ld = LocalDate.now();
            String fd = ld.toString();
            this.date = fd;
            this.type = type;
        }

        public boolean isNewerThan(Contact c) {
            if(this.date.compareTo(c.date) <= 0) {
                return true;
            } else {
                return false;
            }
        }

        public String getType() {
            return type;
        }



    }


    class PhoneContact extends Contact {

        private String phone;

        public PhoneContact(String date, String type, String phone) {
            super(date, type);
            this.phone = phone;
        }

        public String getPhone() {
            return phone;
        }
    }


    public static void main(String[] args) {

    }
}

标签: javaenums

解决方案


推荐阅读