Specifications

Sun Services
Java™ Programming Language
Module 2, slide 15 of 26
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Declaring Constructors
Basic syntax of a constructor:
[<modifier>] <class_name>
(
<argument>*
) {
<statement>*
}
Example:
1 public class Dog {
2
3 private int weight;
4
5 public Dog() {
6 weight = 42;
7 }
8}