Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

static variable and non-static

271944Mar 22 2011 — edited Mar 23 2011
I have a quick question. The following syntax compiles.

private String t = key;

private static String key = "key";



But this doesn't compile.

private String t = key;

private String key = "key";


Can anybody explain how it is treated in java compiler?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 20 2011
Added on Mar 22 2011
12 comments
439 views