Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes In interface if any variable is declared then no need to initialize. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "In interface if any variable is declared then no need to initialize. " Watch "In interface if any variable is declared then no need to initialize. " New topic
Author

In interface if any variable is declared then no need to initialize.

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
In Java class If any variable is declared then no need to initialize the variable. But In interface if any variable is declared then no need to initialize.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
jacob deiter wrote:In Java class If any variable is declared then no need to initialize the variable. But In interface if any variable is declared then no need to initialize.


per the JLS, every "variable" declared in an interface is implicitly public, static, and final.
per the JLS, 9.3.1: Every field in the body of an interface must have an initialization expression, which need not be a constant expression. The variable initializer is evaluated and the assignment performed exactly once, when the interface is initialized.
 
 
subject: In interface if any variable is declared then no need to initialize.