Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:18:49+00:00 2026-06-12T13:18:49+00:00

abstract class Base{ protected abstract void a(); } class Child extends Base{ @Override public

  • 0
abstract class Base{
      protected abstract void a();
}

class Child extends Base{
      @Override
      public void a(){
          //why is this valid
      }
}

Why is that we can’t reduce the visibility but can increase it?

Also I need to implement Template pattern in which the public methods visible can only be of base class.

Example:

abstract class Base{
      public void callA(){
      //do some important stuff
      a();
      }

      protected abstract void a();
}

class Child extends Base{
      @Override
      public void a(){
          //why is this valid
      }
}

Now if java allows to increase visibility then there are two methods visible publicly??

I know interface is one solution but is there some other way out???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:18:50+00:00Added an answer on June 12, 2026 at 1:18 pm

    Why decreasing visibility is not allowed is already explained in other responses (it would break the contract of the parent class).

    But why it is allowed to increase the visibility of a method? First, it would not break any contract, so there is no reason to not allow it. It can be handy sometimes, when it makes sense in the child class for a method to not be protected.

    Second, not allowing it could have the side effect of making impossible sometimes to extend a class and implement an interface at the same time:

    interface Interface1 {
       public void method();
    }
    
    public class Parent {
       protected abstract void method();
    }
    
    public class Child extends Parent implements Interface1 {
       @Override
       public void method() {
       }
       //This would be impossible if the visibility of method() in class Parent could not be increased.
    }
    

    About your second question, you can do nothing about it. You have to trust that the person who implements the child class doesn’t do anything that breaks your implementation. Even if java wouldn’t allow to increase visibility, that would still not fix your problem, because a public method with a different name could be created that calls the abstract method:

    class Child extends Base{
          @Override
          protected void a(){
    
          }
    
          public void a2() {
               a(); //This would have the same problems that allowing to increase the visibility.
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public abstract class MyControllerBase : Controller { protected override void OnActionExecuting(ActionExecutingContext context) { //
I have a base class that extends DataGridView : public abstract class MyDataGridView :
I have an abstract immutable base class that defines enforces child classes to be
Given the following: public abstract class Base { // other stuff public static void
abstract class base { abstract public function test(); public function run() { self::test(); }
abstract class Base {} class A extends Base class B extends Base How do
Let's assume public abstract class Game { // Base } public class Poker :
I have an abstract base class class AbstractClass { Col<AbstractClass> parent public AbstractClass() {
I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have a abstract base class that I have many inherited classes coming off

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.