Basic computer course, C programming language, Education, Engineering Course, Engineering Courses, Maths Coaching, online computer coaching, PGDCA course coaching, programming course, school computer coaching, training, Uncategorized, Web Design course

Why do we need default constructor? tccicomputercoaching.com


Constructor 
is used to initialize an object. In other words, constructor provides memory to an object. Without initializing an object we can’t use its properties.

But there is no need to define or declare a default constructor in Java.The compiler implicitly adds a default constructor in the program if we have not declared or defined it.

default construcrtor

Example-

class Experiment

{

int a=10;

int b=20;

public static void main(String[] argus)

{

Experiment e=new Experiment(); //default constructor//

}

}

The only purpose of the constructor is to set a variable’s default value, which will be zero anyway. This default constructor will be implicitly declared and created by the compiler.

For more information about constructor in Java,Constructor in C++, TCCI.

Call us @ 9825618292

Visit us @ http://www.tccicomputercoaching.com

 

Leave a comment