Java | Constructors | Question 4
Is there any compiler error in the below Java program?
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(); } } |
chevron_right
filter_none
(A) Yes
(B) No
Answer: (A)
Explanation: The main function calls paramaterless 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
Recommended Posts:
- Java | Constructors | Question 2
- Java | Constructors | Question 1
- Java | Constructors | Question 3
- Java | Constructors | Question 5
- Java | Constructors | Question 6
- Java | Constructors | Question 8
- Why Constructors are not inherited in Java?
- Order of execution of Initialization blocks and Constructors in Java
- C++ | Constructors | Question 6
- C++ | Constructors | Question 14
- C++ | Constructors | Question 13
- C++ | Constructors | Question 5
- C++ | Constructors | Question 2
- C++ | Constructors | Question 17
- C++ | Constructors | Question 15



