Skip to content

Exercise_09_05 Static Field Problem #9

Open

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.

Activity

  1. SleekPanther commented on Apr 4, 2017

    @SleekPanther
    Contributor

    I second the idea put forth by @SquirrelCoder

  2. jsquared21 commented on Apr 7, 2017

    @jsquared21
    Owner

    Hi guys,

    I'm great, how are you?

    Thanks for the corrections, I will make the updates once i get some free time, or if you make a pull request i will approve it and i'm sure many followers will appreciate it as well.

    Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions