Java | Constructors | Question 5
Output of following Java program
class Point { int m_x, m_y; public Point(int x, int y) { m_x = x; m_y = y; } public Point() { this(10, 10); } public int getX() { return m_x; } public int getY() { return m_y; } public static void main(String args[]) { Point p = new Point(); System.out.println(p.getX()); } } |
chevron_right
filter_none
(A) 10
(B) 0
(C) compiler error
Answer: (A)
Explanation: it’s a simple program where constructor is called with parameters and values are initialized.
Quiz of this Question
Recommended Posts:
- Java | Constructors | Question 6
- Java | Constructors | Question 1
- Java | Constructors | Question 2
- Java | Constructors | Question 4
- Java | Constructors | Question 8
- Java | Constructors | Question 3
- Why Constructors are not inherited in Java?
- Order of execution of Initialization blocks and Constructors in Java
- C++ | Constructors | Question 17
- C++ | Constructors | Question 2
- C++ | Constructors | Question 8
- C++ | Constructors | Question 7
- C++ | Constructors | Question 3
- C++ | Constructors | Question 5
- C++ | Constructors | Question 4



