Ask Question

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

+5
Answers (1)
  1. 18 February, 09:17
    0
    Option 3 is the right answer for the above question

    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--

    Assign the 1 value to the x variable. 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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Public class Illustrate { private int x; private int y; public Illustrate () { x = 1; y = 2; } public Illustrate (int a) { x = a; } public ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers