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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:22:02+00:00 2026-05-31T13:22:02+00:00

I know that the Java have these serval keywords to identify the variable scope

  • 0

I know that the Java have these serval keywords to identify the variable scope during development, but I would like to know whether this is different when it is in a production environment or just for coder interest? Thanks.

  • 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-31T13:22:03+00:00Added an answer on May 31, 2026 at 1:22 pm

    Accessibility is enforced at runtime as well. If some code tries to access a member that it shouldn’t, then IllegalAccessException or IllegalAccessError is thrown. Here’s a quick demonstration:

    public class AccessTest {
        public int publicNumber;
        private int secretNumber;
    }
    
    public class Client {
        public static void main(String[] args) throws Exception {
            reflection();
            noReflection();
        }
    
        private static void noReflection() throws IllegalAccessException, NoSuchFieldException {
            int a = new AccessTest().publicNumber;
              //                     ^^^^^^^^^^^^ 
              // To be changed to secretNumber in bytecode editor after compilation
    
            System.out.println("Number read: " + a);
        }
    
        private static void reflection() throws IllegalAccessException, NoSuchFieldException {
            AccessTest instance = new AccessTest();
            AccessTest.class.getDeclaredField("publicNumber").get(instance); // <-- Works
            try {
                AccessTest.class.getDeclaredField("secretNumber").get(instance); // <-- Throws IllegalAccessException
            } catch (IllegalAccessException e) {
                System.out.println("Caught IllegalAccessException");
            }
        }
    }
    

    With reflection:

    As it is, the above program outputs:

    Caught IllegalAccessException
    Number read: 10
    

    Without reflection:

    When I use a bytecode editor to change

    getfield com/blah/access/AccessTest/publicNumber I
    

    in method noReflection() to:

    getfield com/blah/access/AccessTest/secretNumber I
    

    the output is:

    Caught IllegalAccessException
    Exception in thread "main" java.lang.IllegalAccessError: tried to access field com.blah.access.AccessTest.secretNumber from class com.blah.access.Client
    at com.blah.access.Client.noReflection(Client.java)
    at com.blah.access.Client.main(Client.java:12)
    

    As Michael mentioned this behavior may be JVM dependent. I ran this on

    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have files named xxx.java.i , xxx.java.d , xxx.jar.i . I know that these
I know that Open Office Database uses a java database backend. Does anyone have
I have an exe that I know was written in java. I understand that
I know that in GWT the java reflection tools isn't emulated, but is there
i know that the JDK consists of all java packages .But what does the
Lately I have come to realize that I should know some of Java for
I know that there have been plenty of topics describing this topic but I
I know that Java enforce the programmer to list all exceptions that will be
OK - I know that Java generics can be a minefield for the unwary,
I always come across articles which claim that Java is interpreted. I know that

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.