I have heard that putting code into the constructor is bad practice by my c++ lecturer and other people
public class Square {
Square(int height,int width) {
IO.println("square");
for(int i = 0; i < height;i++) {
IO.print("\n");
for(int j = 0; j < width;j++) {
IO.print("O");
}
}
}
public static void main(String[] args) {
new Square(3, 7);
}
}
can someone explain to me why putting code in the constructor is bad practice? I understand you can use a method but what is deemed except-able and where can the line be drawn. Is it just for setting the members/attributes? can i at least call a method in the constructor?