SCJP Certification

Sun Certified Java Programmer Certification exam essentials

August 20th, 2010

What is a default constructor?

Java Facts, by Daisy Williams.

A constructor without any parameters is known as a default constructor. When a class is defined without any constructor, the Java compiler provides an implicit default constructor. The implicit default constructor is equivalent to the following implementation:

class name(){
super();
}

When the implicit default constructor of a class is invoked, it implicitly calls the no parameter constructor in the superclass. This action taken by a default constructor ensures that the inherited state of the object is initialized properly. In addition, it initializes all the instance variables in the object to the default value depending on their data type.

The default constructor of a class has the same access modifier with which the class has been declared. For example, the default constructor of a public class is implicitly given the public access. The default constructor of a protected class is implicitly given the protected access. The default constructor of a private class is implicitly given the private access. Otherwise, the default constructor has the default access implied by no access modifier.

Share

Back Top

Responses to “What is a default constructor?”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*