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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:49:34+00:00 2026-06-15T07:49:34+00:00

I have read here that in Java it is possible for two variables having

  • 0

I have read here that in Java it is possible for two variables having same name but different type to co-exist in the same scope. What I mean is this

class test
{
    private int x;
    private double x;
}

But all java IDE do not allow such code. I want to know whether such a code is really syntactically correct, or simply the IDE do not allow such code to prevent ambiguity.

Anyway here is the extract from the website

"If you’re lucky, you might be able to recompile the output from Jad. However, the Java VM has more lenient rules for variable naming than the Java language itself. For instances, a valid class file can have several variables named ‘a’, as long as they have different types. If you decompile such a class, the source code you get will not be valid.

JAD will usually rename the offending fields, and make a recompilable file… the only problem being that the recompiled file won’t be compatible with the original classes."

  • 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-15T07:49:36+00:00Added an answer on June 15, 2026 at 7:49 am

    You cannot have variables having same name (but different type) to exist in the same scope.
    Consider if it was possible then how would the java compiler determine which one you meant.

    Consider this code snippet

    class test
    {
        private int x;
        private double x;
    
        test() //constructor
        {
            System.out.println(x); //Error cannot determine which x you meant
        } 
    }
    

    The java compiler cannot understand which x you are actually referring to. So such a code is not syntactically correct and not compilable.

    However there exists tools such as ClassEditor which can modify the generated class file after it is created. There it is possible to change the name two variables to same.

    However such a class is not necessarily runnable by the java jvm.

    The software which you have quoted i.e JAD can rename such duplicate named variables in the class file so that the source code which you will be getting will actually be syntactically correct

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

Sidebar

Related Questions

I have read so many times, here and everywhere on the net, that mutexes
I have an XML file that I'm trying to read from here , and
I have read here http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/ about how you probably shouldn't be trying to un-flatten
I have read some of the questions and answers here, but it none match
I have read quite a few selcet+update questions in here but cannot understand how
I have read a lot of related topics here regarding this problem but I
Possible Duplicate: comparing contents of two files using python I have a file name
I have read this where found that how to access integer resources in java
I have read some posts on here about not mixing parameters when passing into
I have read a lot of topic here and people tend to store IP

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.