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 abstract
has been interchanged in the above 2 methods.
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.
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 .
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).
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With