Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Why are there no global variables in Java?

4 like 0 dislike
Hello
Why are there no global variables in Java?
please reply me. i am waiting for your reply.
Thanx
asked 1 year ago by DBA-boss (120,990 points)

1 Answer

2 like 0 dislike
 
Best answer
Global variables are considered bad form for a variety of reasons: · Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables).
· State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state.
· When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once.
For these reasons, Java decided to ban global variables.
answered 1 year ago by eagles11 (179,830 points)

Related questions

8 like 0 dislike
0 answers
5 like 0 dislike
1 answer
5 like 0 dislike
1 answer
asked 1 year ago by DBA-boss (120,990 points)
5 like 0 dislike
1 answer
7 like 0 dislike
1 answer
asked 1 year ago by eagles11 (179,830 points)