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 9004257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:51:43+00:00 2026-06-16T00:51:43+00:00

I have have a class A in Java and A has some protected methods,

  • 0

I have have a class A in Java and A has some protected methods, I then have a class B which extends from A so that B can override those protected methods. I then want the ability to have a class C that extends from class B but class C should not be able to call A‘s protected methods. Is there away to do that in Java? Do I just make the parent’s class’s method’s overriden and have them final? i.g.

public class A()
{
     protected void somemethod();
     protected int somevariable;
}

public class B() extends A
{
    @Override
    final protected void somemethod();
        //How do I make some variable final or not accessible to my children?
    }

    public class C() extends B
    {
        //Now I cannot override somemethod! Is that right?
    }
}
  • 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-16T00:51:44+00:00Added an answer on June 16, 2026 at 12:51 am

    No, you cannot prevent a child class from calling a parent’s protected methods. To achieve this, you would have to reduce the method’s visibility, which is not allowed. Making the method final in your class B only means it cannot be overriden in any subclasses.

    The fact that you want disallow calls to protected methods for child classes appears to be a design problem to me. You might want to review how your whole class hierarchy and maybe better isolate the reponsibilites of your classes so that you don’t get into a situation where you have to prevent what would normally be allowed (calling protected methods).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Java class that has some methods: public class Utils {
I have a Java class which has some field annotated with @SearchCriteria(criteria = class1.class2.field)
I have a quite huge Java class that has several imported packages and libraries
I have an application which resides in ROOT. This application has a java class(in
I have a Java class MyPojo that I am interested in deserializing from JSON.
I have a Java class that returns a unicode string... Java has the correct
like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field
I have a Java class which handles both single valued and multi-valued data. Therefore,
I have the following code which does nothing but reading some values from a
I have developed some reusable android component which is basically a class . This

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.