<<< The new keyword in Java | Index | Default constructor >>> |
One of the most common and rudimentary activities inside a constructor is initialization of the object memory.
That is, initialization of the data member attributes.
When data attributes are added to object implementation, each constructor needs to be updated.
public class Planet { int distance; int satellites; double mass; public Planet( int distance, int satellites, double mass ) { this.distance = distance; this.satellites = satellites; this.mass = mass; } }
<<< The new keyword in Java | Index | Default constructor >>> |