Monday, 14 January 2019 00:11

Project X

Written by
Rate this item
(0 votes)

A coworker handed this to me a few years back when we were conducting technical interviews for developers and asked if I could guess what the output would be.

I could not by just looking at it. Maybe you can:

class X {
  int X;
  X(int X) { this(X, X++); this.X = X; }
  X(int X, int XX) { this.X += XX += this.X + X++; }
  int X(int X) { X(this); return X; }
  X X(X X) { X.X += ++x.XX; return new X(X.X); }
}

public class x {
  static int XX;
  static int X(X X) { return X.X; }
  public static void X(int X) { System.out.println(X); }
  public static void main(String[] XXX) {
    X X = new X((new X(++x.XX)).X);
    X(X.X(X.X));
    X(X.X(X).X);
    X(X(X.X(X)));
  }
}

The answer is 3, 9 and 13 each on separate lines.

Steve Cote

Steve has been a systems architect for the telecommunications and electric utility industries creating circuit provisioning systems and smart grid solutions. He is a hands-on architect working with teams to deliver large complex projects. More recently, Steve has been consulting agile teams from Fortune 15 organizations, start-ups, and everything in-between to be more productive with DevOps and agile practices.

More in this category: « Note-Taking for Consultants

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.