In fact, this is very definite. in the definition of a class, the static modifier cannot be used, but the reason is that there is a situation where the class can be defined as static, it is an internal class.
In the following definition, an internal class is implemented:
Package net. moon. insignificant. staticclass; </P> <p> public class staticclassdemo {</P> <p> Public static void main (string [] ARGs) {<br/> staticclassdemo. innerclass Ic = new staticclassdemo. innerclass (); <br/> IC. showmessage ("Hello, world"); <br/>}</P> <p> static class innerclass {<br/> Public void showmessage (string MSG) {<br/> system. out. println (MSG); <br/>}< br/>
The external class staticclassdemo is a common class. We can further modify it to change staticclassdemo to an abstract class. Then, we can include a default implementation in the abstract class. The Code is as follows:
Package net. moon. insignificant. staticclass; </P> <p> public abstract class staticclassdemo {</P> <p> Public static void main (string [] ARGs) {<br/> staticclassdemo. innerclass Ic = new staticclassdemo. innerclass (); <br/> IC. showmessage ("Hello, world"); <br/>}</P> <p> public abstract void showmessage (string MSG ); </P> <p> static class innerclass extends staticclassdemo {<br/> Public void showmessage (string MSG) {<br/> system. out. println (MSG); <br/>}< br/>
Further, we can also use this method to provide the default implementation for the interface. The Code is as follows:
Package net. moon. insignificant. staticclass; </P> <p> Public interface staticclassdemo {</P> <p> Public void showmessage (string MSG ); </P> <p> static class innerclass implements staticclassdemo {<br/> Public void showmessage (string MSG) {<br/> system. out. println (MSG); <br/>}</P> <p> Public static void main (string ARGs []) {<br/> staticclassdemo. innerclass Ic = new staticclassdemo. innerclass (); <br/> IC. showmessage ("Hello, world"); <br/>}< br/>
Next article: Java tip [003]: execution sequence during class initialization