枚举java语言中的修饰符组合的实例代码
枚举java语言中的修饰符组合,代码如下所示:
packagemodel; /*22:372019/7/20*/ /* topclass的修饰符组合 abstractfinalpublic *2*2 warning: abstractfinal冲突 最终,共有2*(2*2-1)=6种修饰符组合用于topclass */ /* publicabstractclassPublicAbstractClass{} publicfinalclassPublicFinalClass{} abstractclassAbstractClass{} finalclassFinalClass{} publicclassPublicClass{} classClass{} 关于constructor的修饰符组合 abstract[DEFAULT]protectedpublic 关于field的修饰符组合 *2*2*2*2 权限静态的瞬态的同步的 private缺省缺省缺省缺省 缺省(notfinal)(notstatic)(nottransient)(notvolatile) protected publicfinalstatictransientvolatile warning: volatilefinal冲突 最终,共有4*2*2*(2*2-1)=48种修饰符组合用于field 关于method的修饰符组合 *2*2*2*2*2 权限静态的同步的本地的 private缺省缺省缺省缺省缺省 缺省(notabstract)(notfinal)(notstatic)(notsynchronized)(notnative) protected publicabstractfinalstaticsynchronizednative warning: abstract和private冲突 abstract和final冲突 abstract和synchronized冲突 abstract和static冲突 abstract和native冲突 所以abstractmethod的修饰符组合只有三种: abstract protectedabstract publicabstract 最终,共有4*2*2*2*2+3=67中修饰符组合用于method */ /** *这个类列举了所有的用于字段的修饰符组合 *├构造器的修饰符组合 *└方法的修饰符组合 *@authorzhangxingshuo */ abstractclassA{ /*fields*/ /*transientandvolatile*/ privatetransientvolatileintprivateTransientVolatileIntMemberField; transientvolatileinttransientVolatileIntMemberField; protectedtransientvolatileintprotectedTransientVolatileIntMemberField; publictransientvolatileintpublicTransientVolatileIntMemberField; //privatefinaltransientvolatileintprivateFinalTransientVolatileIntMemberField=0; //finaltransientvolatileintfinalTransientVolatileIntMemberField=0; //protectedfinaltransientvolatileintprotectedFinalTransientVolatileIntMemberField=0; //publicfinaltransientvolatileintpublicFinalTransientVolatileIntMemberField=0; privatestatictransientvolatileintprivateStaticTransientVolatileIntMemberField; statictransientvolatileintstaticTransientVolatileIntMemberField; protectedstatictransientvolatileintprotectedStaticTransientVolatileIntMemberField; publicstatictransientvolatileintpublicStaticTransientVolatileIntMemberField; //privatefinalstatictransientvolatileintprivateFinalStaticTransientVolatileIntMemberField=0; //finalstatictransientvolatileintfinalStaticTransientVolatileIntMemberField=0; //protectedfinalstatictransientvolatileintprotectedFinalStaticTransientVolatileIntMemberField=0; //publicfinalstatictransientvolatileintpublicFinalStaticTransientVolatileIntMemberField=0; /*nottransientandvolatile*/ privatevolatileintprivateVolatileIntMemberField; volatileintVolatileIntMemberField; protectedvolatileintprotectedVolatileIntMemberField; publicvolatileintpublicVolatileIntMemberField; //privatefinalvolatileintprivateFinalVolatileIntMemberField=0; //finalvolatileintfinalVolatileIntMemberField=0; //protectedfinalvolatileintprotectedFinalVolatileIntMemberField=0; //publicfinalvolatileintpublicFinalVolatileIntMemberField=0; privatestaticvolatileintprivateStaticVolatileIntMemberField; staticvolatileintstaticVolatileIntMemberField; protectedstaticvolatileintprotectedStaticVolatileIntMemberField; publicstaticvolatileintpublicStaticVolatileIntMemberField; //privatefinalstaticvolatileintprivateFinalStaticVolatileIntMemberField=0; //finalstaticvolatileintfinalStaticVolatileIntMemberField=0; //protectedfinalstaticvolatileintprotectedFinalStaticVolatileIntMemberField=0; //publicfinalstaticvolatileintpublicFinalStaticVolatileIntMemberField=0; /*transientandnotvolatile*/ privatetransientintprivateTransientIntMemberField; transientinttransientIntMemberField; protectedtransientintprotectedTransientIntMemberField; publictransientintpublicTransientIntMemberField; privatefinaltransientintprivateFinalTransientIntMemberField=0; finaltransientintfinalTransientIntMemberField=0; protectedfinaltransientintprotectedFinalTransientIntMemberField=0; publicfinaltransientintpublicFinalTransientIntMemberField=0; privatestatictransientintprivateStaticTransientIntMemberField; statictransientintstaticTransientIntMemberField; protectedstatictransientintprotectedStaticTransientIntMemberField; publicstatictransientintpublicStaticTransientIntMemberField; privatefinalstatictransientintprivateFinalStaticTransientIntMemberField=0; finalstatictransientintfinalStaticTransientIntMemberField=0; protectedfinalstatictransientintprotectedFinalStaticTransientIntMemberField=0; publicfinalstatictransientintpublicFinalStaticTransientIntMemberField=0; /*nottransientandnotvolatile*/ privateintprivateIntMemberField; intintMemberField; protectedintprotectedIntMemberField; publicintpublicIntMemberField; privatefinalintprivateFinalIntMemberField=0; finalintfinalIntMemberField=0; protectedfinalintprotectedFinalIntMemberField=0; publicfinalintpublicFinalIntMemberField=0; privatestaticintprivateStaticIntMemberField; staticintstaticIntMemberField; protectedstaticintprotectedStaticIntMemberField; publicstaticintpublicStaticIntMemberField; privatefinalstaticintprivateFinalStaticIntMemberField=0; finalstaticintfinalStaticIntMemberField=0; protectedfinalstaticintprotectedFinalStaticIntMemberField=0; publicfinalstaticintpublicFinalStaticIntMemberField=0; /*constructors*/ privateA(){} A(inti){} protectedA(inti,intj){} publicA(inti,intj,intk){} /*methods*/ privatefinalstaticsynchronizednativevoidprivateFinalStaticSynchronizedNativeVoidMethod(); finalstaticsynchronizednativevoidfinalStaticSynchronizedNativeVoidMethod(); protectedfinalstaticsynchronizednativevoidprotectedFinalStaticSynchronizedNativeVoidMethod(); publicfinalstaticsynchronizednativevoidpublicFinalStaticSynchronizedNativeVoidMethod(); privatestaticsynchronizednativevoidprivateStaticSynchronizedNativeVoidMethod(); staticsynchronizednativevoidstaticSynchronizedNativeVoidMethod(); protectedstaticsynchronizednativevoidprotectedStaticSynchronizedNativeVoidMethod(); publicstaticsynchronizednativevoidpublicStaticSynchronizedNativeVoidMethod(); privatefinalsynchronizednativevoidprivateFinalSynchronizedNativeVoidMethod(); finalsynchronizednativevoidfinalSynchronizedNativeVoidMethod(); protectedfinalsynchronizednativevoidprotectedFinalSynchronizedNativeVoidMethod(); publicfinalsynchronizednativevoidpublicFinalSynchronizedNativeVoidMethod(); privatesynchronizednativevoidprivateSynchronizedNativeVoidMethod(); synchronizednativevoidsynchronizedNativeVoidMethod(); protectedsynchronizednativevoidprotectedSynchronizedNativeVoidMethod(); publicsynchronizednativevoidpublicSynchronizedNativeVoidMethod(); privatefinalstaticnativevoidprivateFinalStaticNativeVoidMethod(); finalstaticnativevoidfinalStaticNativeVoidMethod(); protectedfinalstaticnativevoidprotectedFinalStaticNativeVoidMethod(); publicfinalstaticnativevoidpublicFinalStaticNativeVoidMethod(); privatestaticnativevoidprivateStaticNativeVoidMethod(); staticnativevoidstaticNativeVoidMethod(); protectedstaticnativevoidprotectedStaticNativeVoidMethod(); publicstaticnativevoidpublicStaticNativeVoidMethod(); privatefinalnativevoidprivateFinalNativeVoidMethod(); finalnativevoidfinalNativeVoidMethod(); protectedfinalnativevoidprotectedFinalNativeVoidMethod(); publicfinalnativevoidpublicFinalNativeVoidMethod(); privatenativevoidprivateNativeVoidMethod(); nativevoidnativeVoidMethod(); protectednativevoidprotectedNativeVoidMethod(); publicnativevoidpublicNativeVoidMethod(); privatefinalstaticsynchronizedvoidprivateFinalStaticSynchronizedVoidMethod(){}; finalstaticsynchronizedvoidfinalStaticSynchronizedVoidMethod(){}; protectedfinalstaticsynchronizedvoidprotectedFinalStaticSynchronizedVoidMethod(){}; publicfinalstaticsynchronizedvoidpublicFinalStaticSynchronizedVoidMethod(){}; privatestaticsynchronizedvoidprivateStaticSynchronizedVoidMethod(){}; staticsynchronizedvoidstaticSynchronizedVoidMethod(){}; protectedstaticsynchronizedvoidprotectedStaticSynchronizedVoidMethod(){}; publicstaticsynchronizedvoidpublicStaticSynchronizedVoidMethod(){}; privatefinalsynchronizedvoidprivateFinalSynchronizedVoidMethod(){}; finalsynchronizedvoidfinalSynchronizedVoidMethod(){}; protectedfinalsynchronizedvoidprotectedFinalSynchronizedVoidMethod(){}; publicfinalsynchronizedvoidpublicFinalSynchronizedVoidMethod(){}; privatesynchronizedvoidprivateSynchronizedVoidMethod(){}; synchronizedvoidsynchronizedVoidMethod(){}; protectedsynchronizedvoidprotectedSynchronizedVoidMethod(){}; publicsynchronizedvoidpublicSynchronizedVoidMethod(){}; privatefinalstaticvoidprivateFinalStaticVoidMethod(){}; finalstaticvoidfinalStaticVoidMethod(){}; protectedfinalstaticvoidprotectedFinalStaticVoidMethod(){}; publicfinalstaticvoidpublicFinalStaticVoidMethod(){}; privatestaticvoidprivateStaticVoidMethod(){}; staticvoidstaticVoidMethod(){}; protectedstaticvoidprotectedStaticVoidMethod(){}; publicstaticvoidpublicStaticVoidMethod(){}; privatefinalvoidprivateFinalVoidMethod(){}; finalvoidfinalVoidMethod(){}; protectedfinalvoidprotectedFinalVoidMethod(){}; publicfinalvoidpublicFinalVoidMethod(){}; privatevoidprivateVoidMethod(){}; voidvoidMethod(){}; protectedvoidprotectedVoidMethod(){}; publicvoidpublicVoidMethod(){}; //privateabstractfinalstaticsynchronizednativevoidprivateAbstractFinalStaticSynchronizedNativeVoidMethod(){}; //abstractfinalstaticsynchronizednativevoidabstractFinalStaticSynchronizedNativeVoidMethod(){}; //protectedabstractfinalstaticsynchronizednativevoidprotectedAbstractFinalStaticSynchronizedNativeVoidMethod(){}; //publicabstractfinalstaticsynchronizednativevoidpublicAbstractFinalStaticSynchronizedNativeVoidMethod(){}; //privateabstractstaticsynchronizednativevoidprivateAbstractStaticSynchronizedNativeVoidMethod(); //abstractstaticsynchronizednativevoidabstractStaticSynchronizedNativeVoidMethod(); //protectedabstractstaticsynchronizednativevoidprotectedAbstractStaticSynchronizedNativeVoidMethod(); //publicabstractstaticsynchronizednativevoidpublicAbstractStaticSynchronizedNativeVoidMethod(); //privateabstractfinalsynchronizednativevoidprivateAbstractFinalSynchronizedNativeVoidMethod(){}; //abstractfinalsynchronizednativevoidabstractFinalSynchronizedNativeVoidMethod(){}; //protectedabstractfinalsynchronizednativevoidprotectedAbstractFinalSynchronizedNativeVoidMethod(){}; //publicabstractfinalsynchronizednativevoidpublicAbstractFinalSynchronizedNativeVoidMethod(){}; //privateabstractsynchronizednativevoidprivateAbstractSynchronizedNativeVoidMethod(){}; //abstractsynchronizednativevoidabstractSynchronizedNativeVoidMethod(){}; //protectedabstractsynchronizednativevoidprotectedAbstractSynchronizedNativeVoidMethod(){}; //publicabstractsynchronizednativevoidpublicAbstractSynchronizedNativeVoidMethod(){}; //privateabstractfinalstaticnativevoidprivateAbstractFinalStaticNativeVoidMethod(){}; //abstractfinalstaticnativevoidabstractFinalStaticNativeVoidMethod(){}; //protectedabstractfinalstaticnativevoidprotectedAbstractFinalStaticNativeVoidMethod(){}; //publicabstractfinalstaticnativevoidpublicAbstractFinalStaticNativeVoidMethod(){}; //privateabstractstaticnativevoidprivateAbstractStaticNativeVoidMethod(){}; //abstractstaticnativevoidabstractStaticNativeVoidMethod(){}; //protectedabstractstaticnativevoidprotectedAbstractStaticNativeVoidMethod(){}; //publicabstractstaticnativevoidpublicAbstractStaticNativeVoidMethod(){}; //privateabstractfinalnativevoidprivateAbstractFinalNativeVoidMethod(){}; //abstractfinalnativevoidabstractFinalNativeVoidMethod(){}; //protectedabstractfinalnativevoidprotectedAbstractFinalNativeVoidMethod(){}; //publicabstractfinalnativevoidpublicAbstractFinalNativeVoidMethod(){}; //privateabstractnativevoidprivateAbstractNativeVoidMethod(); //abstractnativevoidabstractNativeVoidMethod(); //protectedabstractnativevoidprotectedAbstractNativeVoidMethod(); //publicabstractnativevoidpublicAbstractNativeVoidMethod(); //privateabstractfinalstaticsynchronizedvoidprivateAbstractFinalStaticSynchronizedVoidMethod(); //abstractfinalstaticsynchronizedvoidabstractFinalStaticSynchronizedVoidMethod(); //protectedabstractfinalstaticsynchronizedvoidprotectedAbstractFinalStaticSynchronizedVoidMethod(); //publicabstractfinalstaticsynchronizedvoidpublicAbstractFinalStaticSynchronizedVoidMethod(); //privateabstractstaticsynchronizedvoidprivateAbstractStaticSynchronizedVoidMethod(); //abstractstaticsynchronizedvoidabstractStaticSynchronizedVoidMethod(); //protectedabstractstaticsynchronizedvoidprotectedAbstractStaticSynchronizedVoidMethod(); //publicabstractstaticsynchronizedvoidpublicAbstractStaticSynchronizedVoidMethod(); //privateabstractfinalsynchronizedvoidprivateAbstractFinalSynchronizedVoidMethod(){}; //abstractfinalsynchronizedvoidabstractFinalSynchronizedVoidMethod(){}; //protectedabstractfinalsynchronizedvoidprotectedAbstractFinalSynchronizedVoidMethod(){}; //publicabstractfinalsynchronizedvoidpublicAbstractFinalSynchronizedVoidMethod(){}; //privateabstractsynchronizedvoidprivateAbstractSynchronizedVoidMethod(); //abstractsynchronizedvoidabstractSynchronizedVoidMethod(); //protectedabstractsynchronizedvoidprotectedAbstractSynchronizedVoidMethod(); //publicabstractsynchronizedvoidpublicAbstractSynchronizedVoidMethod(); //privateabstractfinalstaticvoidprivateAbstractFinalStaticVoidMethod; //abstractfinalstaticvoidabstractFinalStaticVoidMethod; //protectedabstractfinalstaticvoidprotectedAbstractFinalStaticVoidMethod; //publicabstractfinalstaticvoidpublicAbstractFinalStaticVoidMethod; //privateabstractstaticvoidprivateAbstractStaticVoidMethod(); //abstractstaticvoidabstractStaticVoidMethod(); //protectedabstractstaticvoidprotectedAbstractStaticVoidMethod(); //publicabstractstaticvoidpublicAbstractStaticVoidMethod(); //privateabstractfinalvoidprivateAbstractFinalVoidMethod(); //abstractfinalvoidabstractFinalVoidMethod(); //protectedabstractfinalvoidprotectedAbstractFinalVoidMethod(); //publicabstractfinalvoidpublicAbstractFinalVoidMethod(); //privateabstractvoidprivateAbstractVoidMethod(); abstractvoidabstractVoidMethod(); protectedabstractvoidprotectedAbstractVoidMethod(); publicabstractvoidpublicAbstractVoidMethod(); }
ps:Java修饰符
Java语言提供了很多修饰符,主要分为以下两类:
- 访问修饰符
- 非访问修饰符
修饰符用来定义类、方法或者变量,通常放在语句的最前端。我们通过下面的例子来说明:
publicclassclassName{ //... } privatebooleanmyFlag; staticfinaldoubleweeks=9.5; protectedstaticfinalintBOXWIDTH=42; publicstaticvoidmain(String[]arguments){ //方法体 }
访问控制修饰符
Java中,可以使用访问控制符来保护对类、变量、方法和构造方法的访问。Java支持4种不同的访问权限。
- default(即缺省,什么也不写):在同一包内可见,不使用任何修饰符。使用对象:类、接口、变量、方法。
- private:在同一类内可见。使用对象:变量、方法。注意:不能修饰类(外部类)
- public:对所有类可见。使用对象:类、接口、变量、方法
- protected:对同一包内的类和所有子类可见。使用对象:变量、方法。注意:不能修饰类(外部类)。
总结
以上所述是小编给大家介绍的枚举java语言中的修饰符组合的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!