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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:53:12+00:00 2026-06-13T21:53:12+00:00

I have an question which comes under multilevel inheritance in Java. All Three Classes

  • 0

I have an question which comes under multilevel inheritance in Java. All Three Classes are in Same package

I have class A :

public class A {
   protected int x;
}

public class B extends A {
   public void doSomething {
      // x is visible.agreed, as it is a direct subclass of A
   }  
}


public class C extends B {
   public void doSomething {
      // x is still visible, how come? I mean it is at the 2nd level 
     //  I am confused why?
   }  
}

does it like have any significance? or it is behavior which we have to take it by default?

  • 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-13T21:53:13+00:00Added an answer on June 13, 2026 at 9:53 pm

    variable/methods marked with protected modifier are visible to all the classes in the same pacakage and only to subclasses in different packages.
    below are the example cases.

    package a;
    class A{
    protected int x;
    }
    class B extends A{
    //x can be accessed from this class
    } 
    
    class C extends B {
    //x can be accessed from this class
    }
    class D{
    //x can be accesed this class but you will have to create A's instance 
    }
    
    package B 
    class One {
    //cannot access x from this class
    }
    class Two extends A {
    //can access x from this class
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question which I am sure is simple but I have slight
I have a question which is slightly similar to this question on stackoverflow std::cin.clear()
I have a question which is described below: What problems would arise for testing
I have a question which I think involves conditional entropy in the field of
I have a question which may be somewhat silly because I'm pretty sure I
I have a question which involves calling a function with 2 parameters of a
Hey guys i have a question which i have been looking for the answer
this is my first time posting here, I have a question which I have
I have this question in which I have a SQL Server Compact Edition database
I have few Question for which I am not able to get a proper

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.