In addition to inner classes, classes generally cannot have static properties.
An external class static_test and an internal static class Static_class are defined as follows:
class static_test{ static_test () { 1; } Public Static int s_int; Public Static void S_func () { System. out. println (""+S_int);} }
Public classhello{Hello () {} Public voidSetaintnum) {a=num; } Public voidSETB (intnum) {b=num; } Public voidShowa () {System. out. println ("A ="+a); } Public voidShowb () {System. out. println ("B ="+b); } Public Static intA; Public intb; Static classstatic_class{Static_class () {S_int=2; } Public Static intS_int; Public Static voidS_func () {System. out. println ("S_int ="+s_int); } } Public Static voidMain (string[] args) {Hello H1=NewHello (); Hello H2=NewHello (); System. out. println ("H1:"); H1.showa (); H1.seta (4); H1.SETB (2); H1.SHOWB (); System. out. println ("H2:"); H2.showa (); H2.SETB (3); H2.SHOWB (); System. out. println ("h:"); System. out. println ("A ="+hello.a); Static_test St=Newstatic_test (); Static_class SC=NewStatic_class (); Static_test.s_func (); Static_class.s_func (); }}
Output:
When you invoke a static member of an external class and an inner class, you can only invoke it by using the [class name] or [member name], or by using the object to invoke the static member.
Static members are categorized as all, and static members that are called by all instance objects point to static members of the class itself, and if static members are modified, all objects are called with a modified static member.
[JAVA] [Java essays starting from 0] How to use static properties and considerations