Java Puzzle 9: Tweet
Feb 02, 2015Short but challenging, a puzzle that fits in a tweet, exploring the power a superclass has over its subclass:
Java puzzle, write A to win: class B extends A{B(Long i){new B(i/Long.compare(i,i));System.out.println("Win");}} http://t.co/dabnwJIlnP
— Wouter Coekaerts (@WouterCoekaerts) February 2, 2015
Instructions:
- Copy-paste that code unchanged into
B.java
- Write anything you want in
A.java
. - Execute it with
java -Djava.security.manager A
. The security manager is there to avoid you cheat too much. - If it reaches the statement that prints "Win" in
B
, then you won. Post your solution as a comment here below. The comments will not be visible yet, to give everyone a chance to solve it without seeing the solution. Compare your answer to the solution