91 area.setOpaque(true);
92 frame.setContentPane(area);
93 frame.setResizable(false);
94 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 95 frame.pack();
96 frame.setVisible(true);
97 });
99 area.setOpaque(true);
100 frame.setContentPane(area);
101 frame.setResizable(false);
102 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);103 frame.pack();
104 frame.setVisible(true);
105 });
Non-private static members of the parent class are accessible by child classes. However, it is a bad practice to do so, because it obscures where a value was actually declared. Always use only the declaring class to access static members.
class SomeClass {
static Object staticData = null;
}
class SomeChildClass {
public void method() {
// Accessing the static value declared within the parent class through the child class.
SomeChildClass.staticData = this;
}
}
class SomeChildClass {
public void method() {
// We are now accessing the static value through the parent class.
SomeClass.staticData = this;
}
}