Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 27

Given:

public enum USCurrency {

PENNY (1),

NICKLE(5),

DIME (10),

QUARTER(25);

private int value;

public USCurrency(int value) {

this.value = value;

}

public int getValue() {return value;}

}

public class Coin {

public static void main (String[] args) {

USCurrency usCoin =new USCurrency.DIME;

System.out.println(usCoin.getValue()):

}

}

Which two modifications enable the given code to compile? (Choose two.)

    Correct Answer: A, C

    To enable the code to compile, the USCurrency enumeration declaration needs to be nested within the Coin class to make it accessible within that scope. Additionally, the instantiation of the enum should not use the 'new' keyword, as enums in Java are instantiated without it. These modifications ensure that the code is syntactically correct and follows Java's enum instantiation rules.

Discussion
maslacOptions: BC

B&C are correct, only in answer B it should say private, not public. B. Make the USCurrency enumeration constructor private.

asdfjhfgjuaDCVOptions: BC

B&C are correct, only in answer B it should say private, not public. B. Make the USCurrency enumeration constructor private.

steefaandOptions: BC

B and C are correct. Just typo in answer, constructor must be (package) private. Also new isn't used when creating enum values.

r1muka5Options: BC

Correct Answers are B&C