In java can an abstract method be anything other than public? Are abstract methods implicitly public or are they package if you don't specify? (regular methods are implicitly package right?) are there any visibility modifiers that an abstract method can't have? (private strikes me as problematic)
If a method of a class is private, you cannot access it outside the current class, not even from the child classes of it. But, incase of an abstract method, you cannot use it from the same class, you need to override it from subclass and use. Therefore, the abstract method cannot be private.
Abstract classes can have private methods. Interfaces can't. Abstract classes can have instance variables (these are inherited by child classes).
Yes we can have an abstract class without Abstract Methods as both are independent concepts. Declaring a class abstract means that it can not be instantiated on its own and can only be sub classed. Declaring a method abstract means that Method will be defined in the subclass.
By default, all methods are public and abstract until we do not declare it as default and properties are static and final.
abstract
methods have the same visibility rules as normal methods, except that they cannot be private
.
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