Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

simle question public static variable

 
        
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody please explain me the difference below?


run:
test
0



run:
test
11
 
author
Posts: 23879
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This ...

A Ka wrote:Can somebody please explain me the difference below?




doesn't compile. Java statements, that are not declarations, need to be in a code block -- either initializer, constructor, or method. And please don't run code that doesn't compile -- you won't know what you are getting.

Henry
 
Author
Posts: 133
10
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code with a separate statement

won't compile because the separate "n=11" statement is an assignment statement, and you generally can't have an assignment statement outside of any methods. In the other version, the " = 11 " thing is part of the declaration of the "n" variable and that's okay to do.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A Ka wrote:Can somebody please explain me the difference below?


run:
test
0



Neither will it compile nor there is a way to access the statement n=11;
 
I want my playground back. Here, I'll give you this tiny ad for it:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic