This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes doubt on instance initializer and constructor. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt on instance initializer and constructor." Watch "doubt on instance initializer and constructor." New topic
Author

doubt on instance initializer and constructor.

Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100
i hava a some doubt.

1-why interface need a final variable.(what's the use of variable in interface)

2-what is the use of instance initializer even constructor is already for intialization
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
It used to be thought it was useful to put constants in interfaces so they would be available to implementing classes. More modern opinions: try here.
About initialisers: I don’t like them; they are called regardless of which constructor is invoked, so that might be a use.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Campbell Ritchie wrote:About initialisers: I don’t like them; they are called regardless of which constructor is invoked, so that might be a use.


And if you have a situation (like in an anonymous inner class) where constructors cannot be used, then instance initializers are essential. (However, even though I use anonymous inner classes extensively, I don't believe I have ever found it necessary to put an instance initializer in one.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt on instance initializer and constructor.