this inside a constructor, what does it do? [duplicate]

4

Good, can someone tell me what this this does?

public Tempo (){
    this(0,0,0);
} 
public Tempo (int h){

    this(h,0,0);
}
public Tempo ( int h,int m){

    this (h,m,0);
}
public Tempo (int h,int m , int s){
    SetTime(h,m,s);

}
    
asked by anonymous 10.06.2017 / 12:04

1 answer

5

The% construct of% inside the constructor serves to call another constructor.

In other words, this will call the constructor

public Tempo (int h,int m , int s){
    SetTime(h,m,s);
}

It can not be used in a conventional method and must be the first instruction inside the constructor, ie if you want to use it. It's just a way to keep the object initialization logic in just one of the constructors.

    
10.06.2017 / 12:21