Write your answers in a text file and submit your file below. P1: Look at the fo
ID: 3856417 • Letter: W
Question
Write your answers in a text file and submit your file below. P1: Look at the following declaration: enum Color { RED, ORANGE, GREEN, BLUE) a. What is the name of the data type declared by this statement? b. What are the enum constants for this type? c. Write a statement that defines a variable of this type and initializes it with a valid value. P2: Assuming the following enum declaration exists: enum Dog {POODLE, BOXER, TERRIER}. What will the following statements display? a. System. out. println(Dog. POODLE + " "+ Dog. BOXER +" " + Dog. TERRIER): b. System. out. println(Dog. POODLE. Ordinal() + " + Dog. BOXER. Ordinal() "In"+ Dog. TERRIER. Ordinal()) c. Dog myDog = Dog. BOXER: if (myDog. compareTo(Dog. TERRIER) > 0) System. out. println(myDog + "is greater than" + Dog. TERRIER): else System. out. println(myDog + "is NOT greater than" + Dog. TERRIER);Explanation / Answer
P1. a) The name of the data type declared by this statement is Color. The keyword enum declares a new datatype with the name Color which has fixed values.
b). as given in the declaration th enum constans are RED, ORANGE,GREEN,BLUE. the enum constants are declared after declaring the datatype
c). color c = 'blue'
this statement assigns a value yellow to a variable c of the type color and it has been initialised to a value blue.
P2. Before answering the parts let us suppose that enum DOG{ POODLE =0, BOXER=1,TERRIER=2}
a). the output would be 3 as DOG.POODLE= 0 and DOG.BOXER=1 and DOG.TERRIER =2 so, 0+1+2 = 3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.