The following code works perfectly.
public class StaticClass {
public static void main(String[] args) {
L.P h = new L.P();
h.show();
}
}
class L {
static class P {
public void show() {
System.out.println("This is static nested class.");
}
}
}
Then why static nested class “static class WeakClassKey extends WeakReference> ” in java.lang.Thread class is not accessible by “Thread.WeakClassKey t;” in my class?
The source code for java.lang.Thread can be found here: http://www.docjar.com/html/api/java/lang/Thread.java.html [in line# 1984].
StaticClassandLare in the same package andPclass has default (i.e. package private) access modifier. That’s why it is accessible.WeakClassKeyhas the same modifier – but is in a different package. Only classes fromjava.langcan access it.