Skip to content
Related Articles
Open in App
Not now

Related Articles

Default constructor in Java

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 10 Jul, 2018
Improve Article
Save Article

Like C++, Java automatically creates default constructor if there is no default or parameterized constructor written by user, and (like C++) the default constructor automatically calls parent default constructor. But unlike C++, default constructor in Java initializes member data variable to default values (numeric values are initialized as 0, booleans are initialized as false and references are initialized as null).

For example, output of the below program is


class Test {
   int i;
   Test t;
   boolean b;
   byte bt;
   float ft;
public class Main {
    public static void main(String args[]) {
      Test t = new Test(); // default constructor is called.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!