怎么在java中利用枚举对修饰符进行组合

发布时间:2021-03-02 15:11:24 作者:戴恩恩
来源:亿速云 阅读:125

这篇文章主要介绍了怎么在java中利用枚举对修饰符进行组合,此处通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考价值,需要的朋友可以参考下:

Java的特点有哪些

Java的特点有哪些 1.Java语言作为静态面向对象编程语言的代表,实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。 2.Java具有简单性、面向对象、分布式、安全性、平台独立与可移植性、动态性等特点。 3.使用Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。

package model;
top class的修饰符组合
abstract final public
  * 2 * 2
warning:
abstract final 冲突
最终,共有2*(2*2-1)=6种修饰符组合用于top class
*/
/*
public abstract class PublicAbstractClass{}
public final  class PublicFinalClass{}
    abstract class AbstractClass{}
    final  class FinalClass{}
public     class PublicClass{}
        class Class{}
关于constructor的修饰符组合
abstract [DEFAULT] protected public
关于field的修饰符组合
    *  2   *   2   *   2     *  2
权限           静态的     瞬态的     同步的
private    缺省     缺省     缺省      缺省
缺省    (not final) (not static) (not transient) (not volatile)
protected
public     final    static    transient    volatile
warning:
volatile final 冲突
最终,共有4*2*2*(2*2-1)=48种修饰符组合用于field
关于method的修饰符组合
    *  2     *  2   *   2   *    2     *  2
权限                   静态的       同步的     本地的
private   缺省      缺省     缺省        缺省     缺省
缺省  (not abstract)  (not final) (not static) (not synchronized) (not native)
protected
public   abstract     final    static    synchronized    native
warning:
abstract 和 private 冲突
abstract 和 final 冲突
abstract 和 synchronized 冲突
abstract 和 static 冲突
abstract 和 native 冲突
所以abstract method 的修饰符组合只有三种:
     abstract
protected abstract
public  abstract
最终,共有4*2*2*2*2+3=67中修饰符组合用于method
*/
/**
 * 这个类列举了所有的用于字段的修饰符组合
 *         ├构造器的修饰符组合
 *         └方法的修饰符组合
 * @author zhangxingshuo
 */
abstract class A {
  /*fields*/
  /*transient and volatile*/
  private        transient volatile int privateTransientVolatileIntMemberField;
              transient volatile int transientVolatileIntMemberField;
  protected       transient volatile int protectedTransientVolatileIntMemberField;
  public         transient volatile int publicTransientVolatileIntMemberField;
//  private  final    transient volatile int privateFinalTransientVolatileIntMemberField=0;
//       final    transient volatile int finalTransientVolatileIntMemberField=0;
//  protected final    transient volatile int protectedFinalTransientVolatileIntMemberField=0;
//  public  final    transient volatile int publicFinalTransientVolatileIntMemberField=0;
  private     static transient volatile int privateStaticTransientVolatileIntMemberField;
          static transient volatile int staticTransientVolatileIntMemberField;
  protected    static transient volatile int protectedStaticTransientVolatileIntMemberField;
  public     static transient volatile int publicStaticTransientVolatileIntMemberField;
//  private  final static transient volatile int privateFinalStaticTransientVolatileIntMemberField=0;
//       final static transient volatile int finalStaticTransientVolatileIntMemberField=0;
//  protected final static transient volatile int protectedFinalStaticTransientVolatileIntMemberField=0;
//  public  final static transient volatile int publicFinalStaticTransientVolatileIntMemberField=0;
  /*not transient and volatile*/
  private              volatile int privateVolatileIntMemberField;
                    volatile int VolatileIntMemberField;
  protected             volatile int protectedVolatileIntMemberField;
  public               volatile int publicVolatileIntMemberField;
//  private  final          volatile int privateFinalVolatileIntMemberField=0;
//       final          volatile int finalVolatileIntMemberField=0;
//  protected final          volatile int protectedFinalVolatileIntMemberField=0;
//  public  final          volatile int publicFinalVolatileIntMemberField=0;
  private     static       volatile int privateStaticVolatileIntMemberField;
          static       volatile int staticVolatileIntMemberField;
  protected    static       volatile int protectedStaticVolatileIntMemberField;
  public     static       volatile int publicStaticVolatileIntMemberField;
//  private  final static       volatile int privateFinalStaticVolatileIntMemberField=0;
//       final static       volatile int finalStaticVolatileIntMemberField=0;
//  protected final static       volatile int protectedFinalStaticVolatileIntMemberField=0;
//  public  final static       volatile int publicFinalStaticVolatileIntMemberField=0;
  /*transient and not volatile*/
  private        transient      int privateTransientIntMemberField;
              transient      int transientIntMemberField;
  protected       transient      int protectedTransientIntMemberField;
  public         transient      int publicTransientIntMemberField;
  private  final    transient      int privateFinalTransientIntMemberField=0;
       final    transient      int finalTransientIntMemberField=0;
  protected final    transient      int protectedFinalTransientIntMemberField=0;
  public  final    transient      int publicFinalTransientIntMemberField=0;
  private     static transient      int privateStaticTransientIntMemberField;
          static transient      int staticTransientIntMemberField;
  protected    static transient      int protectedStaticTransientIntMemberField;
  public     static transient      int publicStaticTransientIntMemberField;
  private  final static transient      int privateFinalStaticTransientIntMemberField=0;
       final static transient      int finalStaticTransientIntMemberField=0;
  protected final static transient      int protectedFinalStaticTransientIntMemberField=0;
  public  final static transient      int publicFinalStaticTransientIntMemberField=0;
  /*not transient and not volatile*/
  private        int privateIntMemberField;
              int intMemberField;
  protected       int protectedIntMemberField;
  public         int publicIntMemberField;
  private  final    int privateFinalIntMemberField=0;
       final    int finalIntMemberField=0;
  protected final    int protectedFinalIntMemberField=0;
  public  final    int publicFinalIntMemberField=0;
  private     static int privateStaticIntMemberField;
          static int staticIntMemberField;
  protected    static int protectedStaticIntMemberField;
  public     static int publicStaticIntMemberField;
  private  final static int privateFinalStaticIntMemberField=0;
       final static int finalStaticIntMemberField=0;
  protected final static int protectedFinalStaticIntMemberField=0;
  public  final static int publicFinalStaticIntMemberField=0;
  /*constructors*/
  private  A(         ){}
       A(int i      ){}
  protected A(int i,int j   ){}
  public  A(int i,int j,int k){}
  /*methods*/
  private      final static synchronized native void privateFinalStaticSynchronizedNativeVoidMethod();
            final static synchronized native void    finalStaticSynchronizedNativeVoidMethod();
  protected     final static synchronized native void protectedFinalStaticSynchronizedNativeVoidMethod();
  public       final static synchronized native void publicFinalStaticSynchronizedNativeVoidMethod();
  private          static synchronized native void privateStaticSynchronizedNativeVoidMethod();
               static synchronized native void    staticSynchronizedNativeVoidMethod();
  protected         static synchronized native void protectedStaticSynchronizedNativeVoidMethod();
  public          static synchronized native void publicStaticSynchronizedNativeVoidMethod();
  private      final     synchronized native void privateFinalSynchronizedNativeVoidMethod();
            final     synchronized native void    finalSynchronizedNativeVoidMethod();
  protected     final     synchronized native void protectedFinalSynchronizedNativeVoidMethod();
  public       final     synchronized native void publicFinalSynchronizedNativeVoidMethod();
  private             synchronized native void privateSynchronizedNativeVoidMethod();
                   synchronized native void    synchronizedNativeVoidMethod();
  protected            synchronized native void protectedSynchronizedNativeVoidMethod();
  public              synchronized native void publicSynchronizedNativeVoidMethod();
  private      final static       native void privateFinalStaticNativeVoidMethod();
            final static       native void    finalStaticNativeVoidMethod();
  protected     final static       native void protectedFinalStaticNativeVoidMethod();
  public       final static       native void publicFinalStaticNativeVoidMethod();
  private          static       native void privateStaticNativeVoidMethod();
               static       native void    staticNativeVoidMethod();
  protected         static       native void protectedStaticNativeVoidMethod();
  public          static       native void publicStaticNativeVoidMethod();
  private      final           native void privateFinalNativeVoidMethod();
            final           native void    finalNativeVoidMethod();
  protected     final           native void protectedFinalNativeVoidMethod();
  public       final           native void publicFinalNativeVoidMethod();
  private                    native void privateNativeVoidMethod();
                         native void nativeVoidMethod();
  protected                   native void protectedNativeVoidMethod();
  public                    native void publicNativeVoidMethod();
  private      final static synchronized    void privateFinalStaticSynchronizedVoidMethod(){};
            final static synchronized    void    finalStaticSynchronizedVoidMethod(){};
  protected     final static synchronized    void protectedFinalStaticSynchronizedVoidMethod(){};
  public       final static synchronized    void publicFinalStaticSynchronizedVoidMethod(){};
  private          static synchronized    void privateStaticSynchronizedVoidMethod(){};
               static synchronized    void    staticSynchronizedVoidMethod(){};
  protected         static synchronized    void protectedStaticSynchronizedVoidMethod(){};
  public          static synchronized    void publicStaticSynchronizedVoidMethod(){};
  private      final     synchronized    void privateFinalSynchronizedVoidMethod(){};
            final     synchronized    void    finalSynchronizedVoidMethod(){};
  protected     final     synchronized    void protectedFinalSynchronizedVoidMethod(){};
  public       final     synchronized    void publicFinalSynchronizedVoidMethod(){};
  private             synchronized    void privateSynchronizedVoidMethod(){};
                   synchronized    void    synchronizedVoidMethod(){};
  protected            synchronized    void protectedSynchronizedVoidMethod(){};
  public              synchronized    void publicSynchronizedVoidMethod(){};
  private      final static           void privateFinalStaticVoidMethod(){};
            final static           void    finalStaticVoidMethod(){};
  protected     final static           void protectedFinalStaticVoidMethod(){};
  public       final static           void publicFinalStaticVoidMethod(){};
  private          static           void privateStaticVoidMethod(){};
               static           void    staticVoidMethod(){};
  protected         static           void protectedStaticVoidMethod(){};
  public          static           void publicStaticVoidMethod(){};
  private      final               void privateFinalVoidMethod(){};
            final               void    finalVoidMethod(){};
  protected     final               void protectedFinalVoidMethod(){};
  public       final               void publicFinalVoidMethod(){};
  private                       void privateVoidMethod(){};
                             void    voidMethod(){};
  protected                      void protectedVoidMethod(){};
  public                        void publicVoidMethod(){};
//  private  abstract final static synchronized native void privateAbstractFinalStaticSynchronizedNativeVoidMethod(){};
//       abstract final static synchronized native void    abstractFinalStaticSynchronizedNativeVoidMethod(){};
//  protected abstract final static synchronized native void protectedAbstractFinalStaticSynchronizedNativeVoidMethod(){};
//  public  abstract final static synchronized native void publicAbstractFinalStaticSynchronizedNativeVoidMethod(){};
//  private  abstract    static synchronized native void privateAbstractStaticSynchronizedNativeVoidMethod();
//       abstract    static synchronized native void    abstractStaticSynchronizedNativeVoidMethod();
//  protected abstract    static synchronized native void protectedAbstractStaticSynchronizedNativeVoidMethod();
//  public  abstract    static synchronized native void publicAbstractStaticSynchronizedNativeVoidMethod();
//  private  abstract final     synchronized native void privateAbstractFinalSynchronizedNativeVoidMethod(){};
//       abstract final     synchronized native void    abstractFinalSynchronizedNativeVoidMethod(){};
//  protected abstract final     synchronized native void protectedAbstractFinalSynchronizedNativeVoidMethod(){};
//  public  abstract final     synchronized native void publicAbstractFinalSynchronizedNativeVoidMethod(){};
//  private  abstract        synchronized native void privateAbstractSynchronizedNativeVoidMethod(){};
//       abstract        synchronized native void    abstractSynchronizedNativeVoidMethod(){};
//  protected abstract        synchronized native void protectedAbstractSynchronizedNativeVoidMethod(){};
//  public  abstract        synchronized native void publicAbstractSynchronizedNativeVoidMethod(){};
//  private  abstract final static       native void privateAbstractFinalStaticNativeVoidMethod(){};
//       abstract final static       native void    abstractFinalStaticNativeVoidMethod(){};
//  protected abstract final static       native void protectedAbstractFinalStaticNativeVoidMethod(){};
//  public  abstract final static       native void publicAbstractFinalStaticNativeVoidMethod(){};
//  private  abstract    static       native void privateAbstractStaticNativeVoidMethod(){};
//       abstract    static       native void    abstractStaticNativeVoidMethod(){};
//  protected abstract    static       native void protectedAbstractStaticNativeVoidMethod(){};
//  public  abstract    static       native void publicAbstractStaticNativeVoidMethod(){};
//  private  abstract final           native void privateAbstractFinalNativeVoidMethod(){};
//       abstract final           native void    abstractFinalNativeVoidMethod(){};
//  protected abstract final           native void protectedAbstractFinalNativeVoidMethod(){};
//  public  abstract final           native void publicAbstractFinalNativeVoidMethod(){};
//  private  abstract              native void privateAbstractNativeVoidMethod();
//       abstract              native void    abstractNativeVoidMethod();
//  protected abstract              native void protectedAbstractNativeVoidMethod();
//  public  abstract              native void publicAbstractNativeVoidMethod();
//  private  abstract final static synchronized    void privateAbstractFinalStaticSynchronizedVoidMethod();
//       abstract final static synchronized    void    abstractFinalStaticSynchronizedVoidMethod();
//  protected abstract final static synchronized    void protectedAbstractFinalStaticSynchronizedVoidMethod();
//  public  abstract final static synchronized    void publicAbstractFinalStaticSynchronizedVoidMethod();
//  private  abstract    static synchronized    void privateAbstractStaticSynchronizedVoidMethod();
//       abstract    static synchronized    void    abstractStaticSynchronizedVoidMethod();
//  protected abstract    static synchronized    void protectedAbstractStaticSynchronizedVoidMethod();
//  public  abstract    static synchronized    void publicAbstractStaticSynchronizedVoidMethod();
//  private  abstract final     synchronized    void privateAbstractFinalSynchronizedVoidMethod(){};
//       abstract final     synchronized    void    abstractFinalSynchronizedVoidMethod(){};
//  protected abstract final     synchronized    void protectedAbstractFinalSynchronizedVoidMethod(){};
//  public  abstract final     synchronized    void publicAbstractFinalSynchronizedVoidMethod(){};
//  private  abstract        synchronized    void privateAbstractSynchronizedVoidMethod();
//       abstract        synchronized    void    abstractSynchronizedVoidMethod();
//  protected abstract        synchronized    void protectedAbstractSynchronizedVoidMethod();
//  public  abstract        synchronized    void publicAbstractSynchronizedVoidMethod();
//  private  abstract final static           void privateAbstractFinalStaticVoidMethod;
//       abstract final static           void    abstractFinalStaticVoidMethod;
//  protected abstract final static           void protectedAbstractFinalStaticVoidMethod;
//  public  abstract final static           void publicAbstractFinalStaticVoidMethod;
//  private  abstract    static           void privateAbstractStaticVoidMethod();
//       abstract    static           void    abstractStaticVoidMethod();
//  protected abstract    static           void protectedAbstractStaticVoidMethod();
//  public  abstract    static           void publicAbstractStaticVoidMethod();
//  private  abstract final               void privateAbstractFinalVoidMethod();
//       abstract final               void    abstractFinalVoidMethod();
//  protected abstract final               void protectedAbstractFinalVoidMethod();
//  public  abstract final               void publicAbstractFinalVoidMethod();
//  private  abstract                  void privateAbstractVoidMethod();
       abstract                  void    abstractVoidMethod();
  protected abstract                  void protectedAbstractVoidMethod();
  public  abstract                  void publicAbstractVoidMethod();
}

ps:Java 修饰符

Java语言提供了很多修饰符,主要分为以下两类:

修饰符用来定义类、方法或者变量,通常放在语句的最前端。我们通过下面的例子来说明:

public class className {
  // ...
}
private boolean myFlag;
static final double weeks = 9.5;
protected static final int BOXWIDTH = 42;
public static void main(String[] arguments) {
  // 方法体
}

访问控制修饰符

Java中,可以使用访问控制符来保护对类、变量、方法和构造方法的访问。Java 支持 4 种不同的访问权限。

到此这篇关于怎么在java中利用枚举对修饰符进行组合的文章就介绍到这了,更多相关怎么在java中利用枚举对修饰符进行组合的内容请搜索亿速云以前的文章或继续浏览下面的相关文章希望大家以后多多支持亿速云!

推荐阅读:
  1. 怎么在JAVA中利用TreeMap对字符串进行排序
  2. 怎么在Java中利用Streams对异常进行处理

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

java 枚举

上一篇:怎么在java接口中实现一个代理设计模式

下一篇:Java中同步机制的原理是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》