Skip to content

Exercise_09_05 Static Field Problem #9

@SquirrelCoder

Description

@SquirrelCoder

Hi,

How are you Sir?

So there is a problem in Exercise_09_05 , because you have accessed a Static Field using an instance reference

System.out.println(calender.get(calender.MONTH) + "/" +
       calender.get(calender.DAY_OF_MONTH) + "/" + calender.get(calender.YEAR));

The correct way to access a static field, would be through the class name, like the following:

Instantiate a new object:

GregorianCalendar calendar = new GregorianCalendar();

and then access the static field using the GregorianCalendar class itself.

 System.out.println(calendar.get(GregorianCalendar.MONTH) + "/" + 
      calendar.get(GregorianCalendar.DAY_OF_MONTH) + 
       "/" + calendar.get(GregorianCalendar.YEAR));

Thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions