0

two examples of android classes are shown below, they are utility classes that do not extend Activity.

what is the advantage of using example 1, and why is it better than example 2?

example 1

public class SKR {

String[] code;
String[] sub_code;

public SKR(){

    code = new String[87];
    sub_code = new String[87];

    }

}

example 2

public class SKR {

String[] code = new String[87];
String[] sub_code = new String[87];

    public SKR(){


   }

}
Kevik
  • 9,181
  • 19
  • 92
  • 148
  • Also see http://stackoverflow.com/questions/3918578/should-i-initialize-variable-within-constructor-or-outside-constructor and http://stackoverflow.com/questions/24551/best-practice-initialize-class-fields-in-constructor-or-at-declaration – jprofitt Jun 20 '13 at 01:12

1 Answers1

0

It's better to the second in my opinion so the compiler can precompile the code.

But there is no real difference in the code.

Romain
  • 1,390
  • 1
  • 13
  • 27