Next: Classes: Constructors 1: Example
Up: Java Notes
Previous: Classes: Declaration Example
- Creating instance object of a class
- Use of
new
- Constructors with 0 or more parameters (cf. overloaded methods) that initialise member variables
- Default constructor: member variables initialised to null values
- Not methods (Not class members)
- Constructor body starts with
super(...)
: uses body of existing superclass constructor (if present); higher level initialisation done first; No such super()
use in overriding methods
- Access specifiers: private (constructor not available outside the class); protected (constructors accessible by subclasses only), public (constructors available for object instantiation by other objects), package (default, access within the package containing it)
- Example:
Ananda Amatya
9/15/1999