I can not understand how to do this, help who knows.

I know that elementary, but still:

There are two constructors, one constructor (without arguments) must call the second constructor (with an argument of type int ).

 public class MyInitTest { private String a; private double c; { a = "non-static initialization block "; System.out.println(a); } { c = 20.03652; System.out.println(c + a); } static private String string; static private int anInt; static { string = "Static block"; System.out.println(string); } static { anInt = 6; System.out.println(anInt + "Static block"); } public MyInitTest(){ } public MyInitTest(int){ } } 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

3 answers 3

 public class Privet { public Privet(){ this(1); // Этот конструктор вызывает конструктор с параметром } public Privet(int a){ // ... } } 
     public class MyInitTest{ public MyInitTest() { this(1); // вызов второго конструктора } public MyInitTest(int i) { //... } } 
    • yeah ahead))))) - Saidolim

    If you need to call the parent class constructor,

     super(7); 

    if another constructor of the current class, then

     this(8); 
    • @Nofate did not even think that both constructors could be in the same class. - Qwertiy