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

  • Home
  • SEARCH
  • 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 6183007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:17:36+00:00 2026-05-24T01:17:36+00:00

This is my code package alpha ; class A1 { static class A11 {

  • 0

This is my code

package alpha ;

class A1
{
    static class A11
    {
        private
            final // WHAT IS THE EFFECT OF THIS MODIFIER?
            void fun ( String caller )
            {
                System . out . println ( "A11:\t" + caller ) ;
            }
    }

    static class A12 extends A11
    {
        private void fun ( String caller )
        {
            super . fun ( caller + caller ) ;
        }
    }

    public static void main ( String [ ] args )
    {
        A12 a12 = new A12 ( ) ;
        a12 . fun ( "Hello" ) ;
    }
}

I have found that with or without the final mdifer in A1.A11 the program compiles and runs.

I can understand that without the final modifier, A1.A12 can see and thus override the fun method. It is private but they are in the same class so there is no visibility issue.

I can not understand why it works with the final modifier. Should not the overriding in A1.A12 be prohibited?

This is the output of the program with the final modifer in place

java alpha/A1
A11:    HelloHello

If it was simply ignoring the other fun method then

  1. would not the compiler have complained about the super reference
  2. the A11 would not be in the output
  • 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-24T01:17:38+00:00Added an answer on May 24, 2026 at 1:17 am

    Your methods are private.

    Change their visibility to protected to see expected behavior, that is, only when the method is protected, public or default visibility, the concept of overriding even exists.

    Doing something like this —

    class A1
    {
        static class A11
        {
            public
                final // WHAT IS THE EFFECT OF THIS MODIFIER?
                void fun ( String caller )
                {
                    System . out . println ( "A11:\t" + caller ) ;
                }
        }
    
        static class A12 extends A11
        {
            public void fun ( String caller )
            {
                super . fun ( caller + caller ) ;
            }
        }
    
        public static void main ( String [ ] args )
        {
            A12 a12 = new A12 ( ) ;
            a12 . fun ( "Hello" ) ;
        }
    }
    

    will now throw the compile-time exception

    fun(java.lang.String) in A1.A12 cannot override fun(java.lang.String) in A1.A11; overridden method is final
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have the following Groovy code: package fp; abstract class Function { public
I run this code: graphic.addAnimation("standart",new int[] {0,1},1.0,true); which calls the graphic.addAnimation(String,int[],float,boolean) Method: public void
I use this code for connection to my service, but when I put this
Is there ready Emacs code/package to automatically set indent-tabs-mode according to the file being
I have the following code: package ; import flash.display.DisplayObject; import flash.display.Graphics; import flash.display.MovieClip; import
I am having trouble with a HelloWorld Applet. Here is my Java code: package
Here's my code: package com.eggproject_hu.WPECommerceAdminSales.client; import java.lang.Boolean; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; public class AblakVillogo
I am having a problem in this code. what i am trying to do
Any clue why my Android app is hanging on this code block when I
Im playing around with NHibernate 3 alpha but struggling to set up my SessionFactory.

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.