fork download
  1. class Point {
  2. int m_x;
  3. int m_y;
  4.  
  5. // Constructor sin argumentos
  6. public Point() {
  7. this(0, 0); // Llama al constructor con dos argumentos
  8. }
  9.  
  10. // Constructor con argumentos
  11. public Point(int x, int y) {
  12. m_x = x;
  13. m_y = y;
  14. }
  15. }
  16.  
  17. class MyProgram {
  18. public static void main(String[] args) {
  19. Point origin = new Point(); // Crea un objeto Point con (0, 0)
  20. Point p = new Point(5, 5); // Crea un objeto Point con (5, 5)
  21.  
  22. // Imprimir los valores para verificar
  23. System.out.println("Origin: (" + origin.m_x + ", " + origin.m_y + ")");
  24. System.out.println("Point p: (" + p.m_x + ", " + p.m_y + ")");
  25. }
  26. }
  27.  
  28.  
Success #stdin #stdout 0.16s 57944KB
stdin
Standard input is empty
stdout
Origin: (0, 0)
Point p: (5, 5)