• Post Reply Bookmark Topic Watch Topic
  • New Topic

variavle declaration in interface  RSS feed

 
vijay kumarg
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it mandatory to intialize a variable declared in an interface?
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! I think they are.

Try comiling a interface with a variable that is not instanciated and you will get a compile error
= expected
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't declare variables in interfaces. You can only have public static final fields - i.e. constants. These must be given a value within the interface.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you shouldn't do that... Effective Java, topic 17.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!