Answer by Not a bug for Code inside the constructor
There are two alternative to using a constructor to initialize instance members...First one is Instance initialization block, { // whatever code is needed for initialization goes here...
View ArticleAnswer by Braj for Code inside the constructor
Use Initialization block if you have overloaded constructor to avoid repetition of code.public class MyClass{ private List<MyObject> lst; //Initialization block { //----Starting initial code-----...
View ArticleCode inside the constructor
I have the following Java class:public class MyClass{ private List<MyObject> lst; public MyClass(){ //----Starting initial code----- MyAdditionalObject obj=new MyAdditionalObject(); Event e= new...
View Article
More Pages to Explore .....