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());
}
}
|
(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
Last Updated :
28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...