-
-
Save reynir/f8c341eaf7a49722b1388bf0fccb7806 to your computer and use it in GitHub Desktop.
What is the output of this program?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the output of this program? | |
// a) x = 2 | |
// b) x = 3 | |
// c) compile-error | |
// d) runtime exception | |
// e) something else _____ | |
abstract class Eggs { | |
abstract void m(); | |
Eggs() { | |
m(); | |
} | |
} | |
class Toast extends Eggs { | |
private int x = 2; | |
Toast() { | |
m(); | |
x = 3; | |
m(); | |
} | |
public void m() { | |
System.out.println("x = " + x); | |
try { | |
throw new Throwable(); | |
} catch (Throwable t) { | |
t.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
new Toast(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output for reference