O'Reilly logo

Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams by Jamie Jaworski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constructors

Objects are instances of classes that are created using constructors. Every class requires a constructor to create object instances. In fact, if a class does not declare a constructor, the compiler automatically creates a constructor for the class. However, in most cases, you will not rely on the compiler to create a constructor for you—you will declare your own constructors. The following is the syntax of a constructor declaration:

modifers ClassName(arguments) throwsClause {
 // Constructor body
}

The modifiers, arguments, and throws clause are optional. Valid modifiers are public, protected, private, or none. No modifier means that the constructor can only be accessed within the package where the class is declared. The public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required