Java private abstract Method with Example

Java private abstract Method with Example


An abstract class is permitted to have both concrete and abstract methods. In abstract class, no method (either concrete or abstract) can be private. The reasons are very simple and when known looks as of common sense.

Let us make a list to remember.

  1. Abstract methods in an abstract class cannot be private but can be of specifiers public, protected or default.
  2. Similarly, any class cannot be protected or private (can be only public or default). So by this rule, an abstract class cannot be private.
  3. Abstract method or concrete method in abstract class can be protected (a program is available at the end).
  4. As a general rule of Java, the private methods cannot be inherited by subclass. When not inherited, how the abstract methods can be given body (or overridden or implemented) by subclass.
  5. When a method is private, the sub classes can’t access it, hence they can’t override it.
  6. An abstract method cannot be private and also cannot be static, final, native, strictfp, or synchronized.

So, private abstract Method is not possible.

Can abstract method be protected?

Yes, except private, an abstract method can be public, protected or default (in interface all methods should be abstract and public).

1. Following code is possible

Here, the extra condition is private method should be static. But remember, static methods cannot be overridden. The code is just of interest but practically not of usage.

2. Following is also possible. Here both concrete method and abstract method are protected. "protected" method can be used by subclasses only.

5 thoughts on “Java private abstract Method with Example

  1. Rishi Raj

    Hello Rao,

    I tested your statement “Abstract methods or concrete methods in an abstract class cannot be private” with code and got contradictory result.
    I request you to reconsider whether concrete methods can be declared private. My answer to this question is “Yes, they can be private”.

Leave a Reply

Your email address will not be published. Required fields are marked *