Created
September 1, 2016 12:17
-
-
Save tonymorris/501b469c914d0b87cc8b9ac4f22b647c to your computer and use it in GitHub Desktop.
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? (1) | |
// a) m | |
// b) main | |
// c) compile-error | |
// d) runtime exception | |
// e) something else ______ | |
// | |
// Now change the access modifier on the printS method to anything but private. | |
// What is the output of the program now? (2) | |
// a) m | |
// b) main | |
// c) compile-error | |
// d) runtime exception | |
// e) something else ______ | |
class PrivateCtorOverride { | |
private final String s; | |
private void printS() { | |
System.out.println(s); | |
} | |
PrivateCtorOverride(String s) { | |
this.s = s; | |
} | |
public static void main(String[] args) { | |
new PrivateCtorOverride("main").m(); | |
} | |
private void m() { | |
new PrivateCtorOverride("m") { | |
void method() { | |
printS(); | |
} | |
}.method(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment