Method name interchange - public abstract or abstract public

前端 未结 5 1112
故里飘歌
故里飘歌 2020-12-20 12:12

I recently came across the following methods. I tried googling and did an example to see the difference by defining the methods as follows; both seems to be the same. But, i

相关标签:
5条回答
  • 2020-12-20 12:56

    Both code is same and compiler will convert it to same byte code if you decompile the code. However it is general practice (not rule of thumb) to begin code with access specifier rather than other keywords.

    public abstract void methodName();
    abstract public void methodName();
    

    compiler converts both methods to below code

    public abstract void methodName();
    
    0 讨论(0)
  • 2020-12-20 13:09

    It's the same. Don't worry. Two similar declarations of abstract method.

    0 讨论(0)
  • 2020-12-20 13:10

    There is no difference as far as functionality is concerned but, regardless of whichever you choose, it's best to stay consistent.

    That being said, I've almost never seen the abstract public used before. So, from a coding standards point of view, public abstract is probably going to be more easily recognized by more people.

    0 讨论(0)
  • 2020-12-20 13:13
    public abstract void methodName();
    abstract public void methodName();
    

    These two methods are same similar example is

    public static void main(String args[]);
    static public void main(String args[]);
    

    thus above two are same.It is just our wish how we want to write.

    0 讨论(0)
  • 2020-12-20 13:14

    both are modifiers , you can use in any order

    0 讨论(0)
提交回复
热议问题