kyoto dreams
Transformed
Given the code below. Will it compile?
\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0053\u0077\u0061\u0070\u0070\u0065\u0072\u0020\u007b
\u000a\u0020\u0020\u0020\u0020\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0061\u0072\u0067\u0073\u0029\u0020\u007b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0020\u006e\u0031\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0028\u0032\u0036\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0020\u006e\u0032\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0028\u0033\u0039\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0031\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0032\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0073\u0077\u0061\u0070\u0028\u006e\u0031\u002c\u0020\u006e\u0032\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0031\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0032\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u007d
\u000a\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u0073\u0077\u0061\u0070\u0028\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u006f\u0031\u002c\u0020\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u006f\u0032\u0029\u0020\u007b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u0074\u006d\u0070\u0020\u003d\u0020\u006f\u0031\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u006f\u0031\u0020\u003d\u0020\u006f\u0032\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u006f\u0032\u0020\u003d\u0020\u0074\u006d\u0070\u003b
\u000a\u0020\u0020\u0020\u0020\u007d
\u000a\u007d
Caster 3
Given the class below. Will it compile?
If so, what's the output?
If not, how would you fix it?
public class Caster3 {
public static void main(String[] args) {
Object i = new Integer(32);
Integer o = (Integer) i;
out((Object) o);
}
static void out(Object o) {
System.out.println("Object out");
}
static void out(Integer i) {
System.out.println("Integer out");
}
}
Caster2
Given the following class. Will it compile?
If so, what's the output?
If not, how would you fix it?
public class Caster2 {
public static void main(String[] args) {
Object i = new Integer(32);
Integer o = (Integer) i;
out(o);
}
static void out(Object o) {
System.out.println("Object out");
}
static void out(Integer i) {
System.out.println("Integer out");
}
}
Test
Consider the class below.
Will it compile?
If it would, what is the output?
If not, how would you fix it?
public class Test {
public static void main(String[] args) {
if (false) {
System.out.println("world peace");
}
while (false) {
System.out.println("fair and balanced");
}
}
}
Finally
Given the code below. What is the output?
public class Finally {
public static void main(String[] args) {
foo();
}
static void foo() {
try {
System.out.println("try");
System.exit(0);
}
finally {
System.out.println("finally");
}
}
}
Invoke2
Consider the code below. What is the output?
public class Invoke2 {
public static void main(String[] args) {
Integer o = new Integer(47);
out(o);
}
static void out(Object o) {
System.out.println("Object out");
}
static void out(Integer i) {
System.out.println("Integer out");
}
}
Caster
Consider code below.
Will it compile?
If so what is the output?
If not, how would you fix it?
public class Caster {
public static void main(String[] args) {
Integer o = (Integer) new Object();
out(o);
}
static void out(Object o) {
System.out.println("Object out");
}
static void out(Integer i) {
System.out.println("Integer out");
}
}
Invoke
Consider the code below. What's the output.
public class Invoke {
public static void main(String[] args) {
Object o = new Integer(47);
out(o);
}
static void out(Object o) {
System.out.println("Object out");
}
static void out(Integer i) {
System.out.println("Integer out");
}
}
Swapper
Consider the code below. What is the output.
public class Swapper {
public static void main(String[] args) {
Integer n1 = new Integer(26);
Integer n2 = new Integer(39);
System.out.println(n1);
System.out.println(n2);
swap(n1, n2);
System.out.println(n1);
System.out.println(n2);
}
static void swap(Object o1, Object o2) {
Object tmp = o1;
o1 = o2;
o2 = tmp;
}
}
Three
The following code compiles and runs, but only 1 thread is ever created. What is the problem and how would you fix it?
public class T extends Thread {
public static void main(String []args) {
for (int i = 0; i < 10; i++) {
T t = new T();
t.run();
}
}
public void run() {
while (true) {
System.out.println(System.currentTimeMillis());
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {}
}
}
}
Two
Consider the code below.
When run, what is the output and why?
public class A {
private int count = 1;
public static void main(String []args) {
B b = new A().new B();
}
class B {
private int count = 2;
B() {
System.out.println(count);
}
}
}
One
Consider the code below.
1. Will it compile?
2. If so what is the output?
3. If not, why not, and how would you fix it?
public class Foo {
private int count = 1;
public static void main(String []args) {
new Bar();
}
}
class Bar extends Foo {
public Bar() {
System.out.println(count);
}
}