TAILIEUCHUNG - Object-Oriented Programming: Enum types

Object-Oriented Programming: Enum types An enum type is a type whose fields consist of a fixed set of constants; Because they are constants, the names of an enum type's fields are in uppercase letters. | Lecture 3-bis: Enum types Lê Hồng Phương phuonglh@ Department of Mathematics, Mechanics and Informatics, Vietnam National University, Hanoi Enum types ● An enum type is a type whose fields consist of a fixed set of constants. – – The days of the week – ● Compass directions The suits of a card Because they are constants, the names of an enum type's fields are in uppercase letters. 2012-2013 Object-Oriented Programming: Enum types 2 Enum types public enum CompassDirection { NORTH, SOUTH, EAST, WEST } public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } public enum Suit { SPADE, CLUB, DIAMOND, HEART } 2012-2013 Object-Oriented Programming: Enum types 3 The Card class revisited public class Card { private int rank; private String suit; public Card(int rank, String suit) { = rank; = suit; } // . } public class CardTester { public static void main(String[] args) { Card c1 = new Card(2, "Spade"); Card c2 = new Card(2, "Undefined"); } } 2012-2013 Object-Oriented Programming: Enum types We should prevent user from doing this. 4 The Card class revisited public class Card { private int rank; private Suit suit; public Card(int rank, Suit suit) { = rank; = suit; } // . } public class CardTester { public static void main(String[] args) { Card c1 = new Card(1, ); } } 2012-2013 There are only 4 possible suits that a card can take. Object-Oriented Programming: Enum .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.