Home Tutorial Java Scjp Part1 SCJP Module-1 Question-13

 
 

SCJP Module-1 Question-13
Posted on: July 8, 2010 at 12:00 AM
The program given below checks your understating of enum (A new primitive data type) and also check your understating of flow of program.

Given a sample code:

enum Year {
JANUARY, FEBUARY, MARCH, APRIL, MAY, JUNE, JULY
}

class EnumTest {
Year year;

public EnumTest(Year year) {
this.year = year;
}

public void tellItLikeItIs() {
switch (year) {
case JANUARY:
System.out.println("JANUARY is too cold.");
break;

case APRIL:
System.out.println("APRIL is less hot.");
break;

case JULY:
case JUNE:
System.out.println("JUNE is hottest.");
break;

default:
System.out.println("Rest are nice ");
break;
}}

public static void main(String[] args) {
EnumTest firstMonth= new EnumTest(Year.JANUARY);
firstMonth.tellItLikeItIs();
EnumTest thirdDay = new EnumTest(Year.APRIL);
thirdDay.tellItLikeItIs();
EnumTest fifthDay = new EnumTest(Year.JULY);
fifthDay.tellItLikeItIs();
EnumTest sixthDay = new EnumTest(Year.MAY);
sixthDay.tellItLikeItIs();
EnumTest seventhDay = new EnumTest(Year.JUNE);
seventhDay.tellItLikeItIs();

}}

What will be the result of above code ?

(1)    JANUARY is too cold.
        APRIL is less hot.
        JUNE is hottest.
        Rest are nice
        JUNE is hottest.

(2)    JANUARY is too cold.
        JUNE is hottest.
        JUNE is hottest.
        APRIL is less hot.
        JUNE is hottest.

(3)    JUNE is hottest.
        JUNE is hottest.
        Rest are nice
        APRIL is less hot.
       JANUARY is too cold.

(4)    APRIL is less hot.
        JUNE is hottest.
        Rest are nice
        JUNE is hottest.
        JANUARY is too cold.

Related Tags for SCJP Module-1 Question-13:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.