• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Accessing Interface Variables ?  RSS feed

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Given the code below, i cannot figure out why Class B compiles fine, whereas Class A doesn't...
the compiler says "Syntax error on token ";",,expected".

Any idea?
Thank you!
Dave

 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside the class (and outside of any methods or initialization blocks) you can only have variable declarations. You cannot initialize a variable in a separate statement. Initializing with declaration is allowed as after all it is a declaration. So if you want to initialize i in class A, then either initialize it in the declaration or in a initializer block...
 
Davide Crudo
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!

Dave
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Well, if you want the code to run then as Ankit said either Line 1 or Line 2 are the valid ways of initializing the variable i. In case of static variables you could use the static initialization block instead of instance initialization block.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!