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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:50:22+00:00 2026-05-28T17:50:22+00:00

I got this compiler error: You cannot reduce the visibility of a inherited method.

  • 0

I got this compiler error:

You cannot reduce the visibility of a inherited method.

I have the following code

class Parent {      
    public void func() {
        System.out.println("in Parent");
    }
}

public class TestClass extends Parent {    
    public static void main(String args[]) {
        parent obj=new TestClass();
        obj.addTest();
    } 

    private void func() {
        System.out.println("in child");         
    }
}

Here parent class has func() method which is public and overridden by the subclass TestClass which is private. Now the compiler throws the error that I cannot the reduce the visibility. To say technically, whenever I create a object of TestClass assigning to the type parent object, since the func() method is overridden, TestClass’s func() is going to get called always, then why we should take care of visibility? whats the reason behind this error ? Can someone explain me clearly ?

  • 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-05-28T17:50:24+00:00Added an answer on May 28, 2026 at 5:50 pm

    It’s because the subclass has visibility of private for the void func() method, but the superclass has visibility public.

    If your code was allowed to compile, it would explode at runtime if you did this:

    parent p = new TestClass();
    p.func(); // boom - func is public in parent, but TestClass's impl is private, so no access would be allowed
    

    To “fix” this, make the subclass’s func method public:

    public class TestClass extends parent {
        ...
        public void func() { // give it public visibility
            System.out.println("in child");         
        }
    }
    

    And please use standard naming conventions; in this case “classes should start with a capital letter” – i.e Parent not parent

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

Sidebar

Related Questions

I'm assuming this is not possible because I got the following error: error C3533:
Consider this code: template <typename T> class String { public: ... String(T* initStr) {
I cannot understand why my compiler (MSVC++2010) doesn't like this code: // get_sum(filename as
so I've got this: class SettingBase { public: virtual ~SettingBase() { } }; template<typename
I got this error when I tried to compile an application that includes the
Got this line of code here but its not working. private void Button_Click(object sender,
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I got this error today when trying to open a Visual Studio 2008 project
got this code from a website that helped me in creating buttons and stuff.
I've got the following classes: class A { void commonFunction() = 0; } class

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.