Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise_09_05 Static Field Problem #9

Open
SquirrelCoder opened this issue Apr 4, 2017 · 2 comments
Open

Exercise_09_05 Static Field Problem #9

SquirrelCoder opened this issue Apr 4, 2017 · 2 comments

Comments

@SquirrelCoder
Copy link

SquirrelCoder commented Apr 4, 2017

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.

@SleekPanther
Copy link
Contributor

I second the idea put forth by @SquirrelCoder

@jsquared21
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants