2
It is always seen as a good practice of programming if we create a class for the object, where we have the constructor and make the methods and another class where we instantiate several objects of the previously created class.
However, I would like to know if it is considered inelegant or a bad style you create the objects in the same class where you created the methods and constructors.
For example, if we have a very simple program, like this 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();
}
}
This can be considered bad practice?