It is always seen as a good programming practice if you create a class for the object, where we have the constructor and we make the methods and another class where we instantiate several objects of the class created previously.
However, I would like to know if it is considered to be inelegant or a bad style to create the objects in the same class where you created the methods and constructors.
For example, if we have a very simple program, like the one below:
public class Main {
private int var1, var2, soma;
public Main(int var1, int var2) {
this.var1 = var1;
this.var2 = var2;
}
public void sum(){
soma = var1 + var2;
System.out.println("resultado = " + soma);
}
public static void main(String[] args) {
Main m = new Main(2,5);
m.sum();
}
}
Can this be considered bad practice?