Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 JavaScript Promises Essentials this week in the JavaScript 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: 39755
    
  28
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: 18860
    
    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.