This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static final" Watch "Static final" New topic
Author

Static final

Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114

Answer given is line 1,2 and 3 all give compile time error.
I think line 1 coz is ambigious, line 3 coz all var in interface are static and final and hence value cannot be changed. But why line 2 as result will be assigned to new var isnt it???
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
to complete an expression you shold have both RightHandSide and LeftHandSide proper expression.
Your expressoin is incomplete. You must have some variable at RHS, then this stmt will become complete and will complile.
CMIW
HTH


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
Thnx that was silly of me isnt it?
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
we all do silly mistakes ..
All The Best ..
Terrence White
Ranch Hand

Joined: Jun 26, 2002
Posts: 39
Why does
System.out.println (star) ;//1
give an error?
Amir Ghahrai
Ranch Hand

Joined: Jun 19, 2002
Posts: 110
star is not declared as static. static methods can only access static members. since main is static, it cannot access the non-static member variable star.


Amir
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Amir,
But in JLS it is given that
Every field declaration in the body of an interface is implicitly public, static, and final.
http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#238680
Please clarify.
Thx
Veena


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
If you compile this code, you should get the following output:

The compiler explanations are self-explanatory...
- on line 1, there is an ambiguous field access (nothing to do with static) (JLS 8.3.3.3 Example: Multiply Inherited Fields)
- line 2 is not a statement as pointed out by Ravish (JLS 14.8 Expression Statements)
- on line 3, we try to assign a value to a final variable. (JLS 4.5.4 final Variables)
[ July 02, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Amir Ghahrai
Ranch Hand

Joined: Jun 19, 2002
Posts: 110
Veena, forgive my carelessness. I noticed my terrible mistake, right after I hit the "reply post" button.
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Amir,
That is ok.We learn by mistakes.
Veena
 
wood burning stoves
 
subject: Static final
 
Similar Threads
Constructors
Questions on innerclass and interface
Subclass
Stars program help
Local Inner Class