Loading data in constructors and not in constructors

Posted by Richeve S. Bebedor on Stack Overflow See other posts from Stack Overflow or by Richeve S. Bebedor
Published on 2010-06-08T13:19:38Z Indexed on 2010/06/08 13:32 UTC
Read the original article Hit count: 263

Filed under:
|

I just want to know the difference between loading the data inside the constructor and loading the data outside the constructor but not inside any methods

example: Loading inside constructor

public class Model{
   Object testobject;

   public Model(){
      testobject=new Object();
   }

}

VS

example: Loading outside constructor

public class Model{
   Object testobject=new Object();

   public Model(){
   }

}

© Stack Overflow or respective owner

Related posts about java

Related posts about constructor