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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:52:01+00:00 2026-05-30T18:52:01+00:00

class X1 { private final void show() { … } } class X2 extends

  • 0
class X1
{
    private final void show() { ... }
}

class X2 extends X1
{
    private final void show() { ... }
}

Question 1

The code is compiling without any errors. Since the final keyword prevents methods from being overidden, why does the code compile?

Question 2

If I remove the private keyword from both show methods, the code doesn’t compile as expected. Why?

  • 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-30T18:52:02+00:00Added an answer on May 30, 2026 at 6:52 pm

    In X2, the method is not the same method, it’s shadowing the method in X1. Since the method in X1 is private, X2 has no awareness of it and thus is able to reuse the method signature. So, when you have an X2 object and you call show, it will use X2’s show. When you have an X1 object, it will use X1’s show.

    If you used the @Override annotation on X2, it would give a warning that the method to be overridden doesn’t exist (or error, not 100% sure).

    This is obviously not a good idea to use the same method signature as someone looking at it later could get very confused and it definitely doesn’t make clear your intentions.

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

Sidebar

Related Questions

private class DownloadLargeFileTask extends AsyncTask<Void, Void, Void> { private final ProgressDialog dialog; public DownloadLargeFileTask(ProgressDialog
private class ExecuteLocations extends AsyncTask<String, Void, Void>{ private final ProgressDialog dialog = new ProgressDialog(ListProfiles.this);
I've got a class somewhat like this: public class Test { private final List<ISomeType>
class Temp { private: ~Temp() {} friend class Final; }; class Final : virtual
class String { private: char* rep; public: String (const char*); void toUpper() const; };
class B{ private: void DoSomething(); } class W{ private: class D: public B{ }
Let's see the following code snippet in Java. package common; final public class Main
I have the following Model class: package com.swaranga.model; public final class Book { private
public class VideoDemo extends Activity { private VideoView video; private MediaController ctlr; File clip=new
The following code in Java uses varargs to overload methods. final public class Main

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.