Advertisement
Guest User

Java puzzle

a guest
May 24th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package com.company;
  2.  
  3. class X1 {
  4.     private final int x1 = 41;
  5.     private X1 X1;
  6.     public X1(X1 x1) { X1 = x1; }
  7.     void print() {
  8.         System.out.println(x1);
  9.     }
  10. }
  11.  
  12. class X2 {
  13.     private final int x2 = 42;
  14.     private X2 X2;
  15.     public X2(X2 x2) { X2 = x2; }
  16.     void print() {
  17.         if (!X2.equals(this)) System.out.println(x2);
  18.     }
  19. }
  20.  
  21. class X3 {
  22.     private final int x3 = 43;
  23.     private X3 X3;
  24.     void X3(X3 x3) { X3 = x3; }
  25.     void print() {
  26.         if (X3.equals(this)) System.out.println(x3);
  27.     }
  28. }
  29.  
  30. public class Main {
  31.     public static void main(String[] args) {
  32.         // your code goes here
  33.         // print x1, x2 and x3 by invoking class print()
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement