Open In App

Java | Constructors | Question 4

Like Article
Like
Save
Share
Report

Is there any compiler error in the below Java program? 

Java




class Point {
    int m_x, m_y;
    public Point(int x, int y) {    m_x = x;    m_y = y;  }
    public static void main(String args[])
    {
      Point p = new Point();
    }
}


(A)

Yes

(B)

No


Answer: (A)

Explanation:

The main function calls parameterless constructor, but there is only one constructor defined in class which takes two parameters. Note that if we write our own constructor, then compiler doesn\’t create default constructor in Java. This behavior is same as C++.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads