Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method name interchange - public abstract or abstract public

Tags:

java

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 need to know if it's really the same ?

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

Note: public and abstracthas been interchanged in the above 2 methods.

like image 393
Sharon Watinsan Avatar asked Dec 04 '12 17:12

Sharon Watinsan


People also ask

Can a method return an abstract class?

In Java, a method can return an abstract class or interface type. What will actually be returned is an object that implements that interface, or extends that abstract class.

Can abstract class have subclass?

Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract .

Can abstract class extend another class in Java?

In Java, abstract means that the class can still be extended by other classes but that it can never be instantiated (turned into an object).

How can use abstract class without extend?

You can't instantiate an abstract class needs an subclass to implement specific methods. You can access its method with an anonymous class for example: new HttpURLConnection() { /* here you need to implement many empty methods */ }. getOutputStream();


1 Answers

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.

like image 70
NemesisX00 Avatar answered Sep 20 '22 07:09

NemesisX00