Section A.9. Constructors


[Page 549 (continued)]

A.9. Constructors

Constructors are used to initialize the fields in a newly created object. The syntax for a constructor is

visibility ClassName(parameterList) {    // statements in the constructor }


Constructors are usually defined with public visibility. Notice that they do not have a return type. The name on a constructor must match the class name.



Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net