Java | Constructors | Question 5

Output of following Java program

filter_none

edit
close

play_arrow

link
brightness_4
code

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


(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



My Personal Notes arrow_drop_up