Constructor Requirement…

Java does not actually require an explicit constructor in the class description. If you do not include a constructor, the Java compiler will create a default constructor in the byte code with an empty argument. This default constructor is equivalent to the explicit constructor.

Example:

class sample

{

private:

int a, b;

public:

….

}

This sample class doesn’t contain any constructor. But the java compiler will create a default constructor in the byte code with an empty argument… sample() { }

If a class includes one or more explicit constructors like …

class sample

{

private:

int a, b;

public:

sample(int a, int b)

{

this.a=a;

this.b=b;

}

}

then the java compiler does not create the default constructor “sample(){}”.

Advertisements