207k views
2 votes
Public class Illustrate

{
private int x;
private int y;

public Illustrate()
{
x = 1;
y = 2;
}

public Illustrate(int a)
{
x = a;
}

public void print()
{
System.out.println("x = " + x + ", y = " + y);
}

public void incrementY()
{
y++;
}
}
What does the default constructor do in the class definition above?

1. Sets the value of x to 0
2. There is no default constructor.
3. Sets the value of x to 1
4. Sets the value of x to a

User Isy
by
5.6k points

1 Answer

2 votes

Answer:

Option 3 is the right answer for the above question

Step-by-step explanation:

The Constructor is used to give the memory for the object. It defines with the name of the class. when the constructor is defined without any argument value then it is known as default constructor.

In the Question's program's segment, the default constructor is public and defined by "Illustrate()" name. which works is as follows--

  1. Assign the 1 value to the x variable.
  2. Assign the 2 value to the y variable.

Hence the option 3 is correct because it states that the x variable value is set to the 1 which is right as described above but the other option is not correct because--

  • Option 1 states that the value of x variable is set to 0 but the x variable is set to 1 in the default constructor.
  • Option 2 states that the default constructor does not exist but there is a default constructor inside the class.
  • Option 4 states that the value of x variable is set to a but the x variable is set to 1 in the default constructor.
User Dinu
by
6.1k points