Browsing index pages (3 articles)
↧
Code 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 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 ArticleAnswer 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 Article
Browsing index pages (3 articles)