Skip to main content

Default Constructors (by Mala Gupta, Author of "OCA Java SE 7 Programmer I Certification Guide")

August 18, 2012


Constructors are special methods defined in a class that create and return an object of the class in which they're defined. Constructors have the same name as the name of a class and they don't specify a return type, not even a void. Constructors come in two flavors: user-defined constructors and default constructors. In this article, based on chapter 3 of OCA Java SE 7 Programmer I Certification Guide, author Mala Gupta discusses default constructors.

As you may know, a constructor is used to create an object. What happens if you don't define any constructor in a class? The following is an example of class Employee that doesn't define a constructor:


class Employee {

Manning Publications Co. is a publisher of computer books for professionals.
Related Topics >> Programming   |   Featured Article   |   

Comments

Constructors are used to assign initial values to instance ...

Constructors are used to assign initial values to instance variables of the class. A default constructor with no arguments will be called automatically by the Java Virtual Machine (JVM).

Thank you

Thank you

This is very interesting article thanks.

This is very interesting article thanks.