what do you understand by constructor & how it is different from methods in java. code example
Example 1: how to create a constructor in java
class Other{
public Other(String message){
System.out.println(message);
}
}
class scratch{
public static void main(String[] args) {
Other method = new Other("Hey");
//prints Hey to the console
}
}
Example 2: calling this in constructor java
In Java another constructor of the same class can be called from a
constructor via this().
Note however that this has to be on the first line.