Professional Documents
Culture Documents
Writing Constructors in Java: Msury - Mahunnah@ifm - Ac.tz
Writing Constructors in Java: Msury - Mahunnah@ifm - Ac.tz
Dr. Mahunnah, M
msury.mahunnah@ifm.ac.tz
https://mahunnah.wordpress.com/
Constructors
A constructor is a special method that is used to set up an object
when it is initially created
The Die constructor is used to set the initial face value of each
new die object to one
Constructors
Note that a constructor has no return type specified in the method
header, not even void
...
}
Initializing objects
Currently it takes 3 lines to create a Point and initialize it:
Point p = new Point();
p.x = 3;
p.y = 8; // tedious
p1 x y