Must-do problems: Constructors
120 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)In every problem the objects are created only through constructors you write: one full constructor that sets the fields, and shorter ones that call it with this(...). Write the class first, check it on the samples, and run every test before opening a hint.
What you will learn
- Write a full constructor and shorter ones that fill in defaults with
this(...) - Keep rules such as "always in lowest terms" or "always a valid date" inside the constructor
- Copy objects and arrays in a constructor so later changes cannot reach them
- Build objects that hold references to other objects, and never leave a field
nullby accident
Sign in to continue this lesson
Create an account to read every lesson, practise with the exercises and keep track of your progress.