×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Java Examples : if-else Programs JAVA Methods
JAVA Constructor and Destructor - Java
18223    Arnab De    01/07/2017

What is Constructor?[ICSE 2014]

Constructor is method in a class which is initialised object variables, when an object is create.

What are the characteristics of a constructor?

  • A constructor has the same name as the class name.
  • A constructor has no return type, not even void.
  • Access specifies of the constructors are generally public.
  • A constructor is automatically called on object creation.
softetechnologies

When is a constructor called?[ICSE 2014]

A constructor is called automatically during object creation.

How many Types of constructor possible in java?

There are three types of constructor possible in java

  1. Default Constructor: If programmers do not specify any constructor, then compiler automatically define a constructor called default constructor. If programmers specify any constructor then supply of the default constructor is stop.
  2. Null Constructor: This type of the constructor has not received any parameter. It is generally initialised the objects with default values.
  3. Parameterised Constructor: This type of the constructor has received one or many parameters. It is generally initialised the objects with customised values.
softetechnologies

What is the difference between a default constructor and a null constructor?

Null constructor is defined by the programmers and initial values are also determined by the programmers. But default constructor is supplied by constructors it doesn’t accept any parameters and initial values are not defined by programmers.

What is the difference between a default constructor and a parameterised constructor?

A default constructor doesn’t accept any parameters. A parameterised constructor accepts parameters.

What does the default constructor provided by the compiler do?

The default constructor provided by the compiler initializes all instances variables to their default values. It initialises integers to 0, floating point numbers to 0.0, boolean values to false and objects to null.

softetechnologies

What is a destructor?

A destructor is a method which is executed when the object is removed from computer’s memory.

Explain the concept of constructor overloading with an example. [ICSE 2011]

A class can have more than one constructor with different singature. This is known as constructor overloading.
Example:

class Car 
{
    int color;
    public Car() { color = -1;}
    public Age(int cl) {color = cl;}

}

Java Examples : if-else Programs JAVA Methods
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Nelson Mandela
An educated, enlightened and informed population is one of the surest ways of promoting the health of a democracy.
Nelson Mandela
1198
60.61
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44721
01/01/2018     36882
25/06/2018     36855
28/06/2017     34896
02/08/2017     33492
01/08/2017     27840
06/07/2017     27613
15/05/2017     27180
14/07/2017     22943
11/09/2018     21679
softetechnologies