Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

Explain the init method in Java?

Asked by Aishwarya Jhadav Oct 6, 2022 2.8K views 1 answer
Share

About this question

 Is there any purpose for declaring an init() method for a type?


I'm not asking whether we should prefer init() over a constructor or how to avoid declaring init().


I'm asking if there is any rationale behind declaring an init() method (seeing how common it is) or if it's a code smell and should be avoided.


The init() idiom is quite common, but I have yet to see any real benefit.


I'm talking about types that encourage initialization via a method:


class Demo {
    public void init() {
        //...
    }
}

When will this ever be of use in production code?


Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.