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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:59:06+00:00 2026-05-31T05:59:06+00:00

I mean, if I declare any access modifier in Java, that modifier can be

  • 0

I mean, if I declare any access modifier in Java, that modifier can be circumvented (package-private and protected – package injection; any – reflection). I know that declaring this stuff helps to understand and organize the code, but besides that, are there any technological reasons or inherent Java functionality?

Thank you guys for wonderful response. I only regret I can tag only one answer as accepted.

  • 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-31T05:59:08+00:00Added an answer on May 31, 2026 at 5:59 am

    Yes, they can be circumvented. The example of dependency injection which you pointed out is actually a useful case of circumvention. Injection to private members doesn’t pollute interfaces and isn’t easy to muddle with at run-time. However to see the core benefit, think of it like you’re a software architect presiding over a very lazy or inexperienced team.

    Remember that well-factored objects should have high cohesion, and loose coupling. High cohesion means that an object deals with the concerns it’s semantically meant to deal with, nothing more, nothing less. Loose coupling means that objects depend on interfaces rather than specific implementations. Remember that the benefit to doing this is that it makes your code much easier to read, understand, test, and change. This reduces cost and in general makes stakeholders happy. As an architect, this is what you care about. The hypothetical lazy/inexperienced team in question only cares about immediately finishing whatever tasks are in their queue, even at the expense of quality and future productivity.

    Access modifiers show some of the intent behind the interface defined for an object. Generally if you’re writing well-factored code, you almost always only have need for public and private modifiers. In the rare case where a concern can’t be easily/clearly separated into a single cohesive object, there’s also the “protected” keyword which allows limited external access from objects which should logically share the concern in question.

    A better, though arguably more cumbersome, way of expressing the intent behind an interface is design by contract, which uses a much more robust set of interface annotations in order to allow preprocessing tools to enforce interface rules.

    tl;dr:

    Compiler enforcement of access modifiers is wonderful. The compiler puts up a pretty good barrier of inconvenience to those who would otherwise be happy reducing the cohesion and increasing the coupling of your codebase in order to cross off their immediate task quicker.

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

Sidebar

Related Questions

If std::vector and friends are self resizing, does that mean if I declare a
I want to know how i can declare and use a global NSMutable array
Is there any way to declare a list object of anonymous type. I mean
In Java we can declare an array using the following: String[] array = new
I mean, how does Java decide which protocols are available? I run some code
I mean, I always was wondered about how the hell somebody can develop algorithms
I mean 100+ MB big; such text files can push the envelope of editors.
Are there any scenarios where usage of Hibernate's extra lazy loading can be dangerous?
I am wondering if there is any way to declare a byte variable in
I need to know if my program can write files to the disk (HDD,

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.