I am studying for my certification exam, and I run into this example that compiles and runs, but the problem is that I do not think that it should compile, since the method is private and we are trying to invoke a private method from an instance of the class. Can someone please explain to me why it works?
Here is the code:
public class Test {
public static void main(String[] args) {
Test instance = new Test();
System.out.println(instance.number());
}
/* protected */ private int number() {
try {
new RuntimeException();
} finally {
return 1;
}
}
}