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

 
 

Share on Google+Share on Google+
SCJP Module-1 Question-13
Posted on: July 8, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-1 Question-13:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com