Thanks for this video! Could you explain when a constructor is needed? If I write a class Test I can create an object by typing class Test test = new class. So when/why would I need a constructor?
A constructor is a special method in a class that is used to initialize objects. While it’s true that you can create an object without explicitly defining a constructor (as many languages like Java provide a default constructor automatically), constructors become essential when you want to set initial values, encapsulate initialization logic, avoid repetitive code... let us know if this answers your question!
Good content! Kudos!
Thanks for this video!
Could you explain when a constructor is needed? If I write a class Test I can create an object by typing class Test test = new class.
So when/why would I need a constructor?
A constructor is a special method in a class that is used to initialize objects. While it’s true that you can create an object without explicitly defining a constructor (as many languages like Java provide a default constructor automatically), constructors become essential when you want to set initial values, encapsulate initialization logic, avoid repetitive code... let us know if this answers your question!