Java Global Variable: Declaration & Examples


Choose an answer and hit 'next'. You will receive your score and answers at the end.

question 1 of 3

Which of the following creates a constant that cannot be changed, but may be referenced by other classes in Java?

Create Your Account To Take This Quiz

As a member, you'll also get unlimited access to over 79,000 lessons in math, English, science, history, and more. Plus, get practice tests, quizzes, and personalized coaching to help you succeed.

Try it risk-free
Try it risk-free for 30 days. Cancel anytime
Already registered? Log in here for access

1. Examine the following Java code. It accesses a variable from another class. Which of the following correctly declares this variable so that the code below will compile?

2. Why doesn't Java support truly global variables?

Create your account to access this entire worksheet
A Premium account gives you access to all lesson, practice exams, quizzes & worksheets
Access to all video lessons
Quizzes, practice exams & worksheets
Certificate of Completion
Access to instructors
Create an account to get started Create Account

About This Quiz & Worksheet

With the use of this quiz and worksheet combination, you can review how much you know about global variables in Java. Questions ask about code that could create an unchangeable constant, and setting the correct value of a static variable grade.

Quiz & Worksheet Goals

Using the questions of the quiz, you can see what you know about the following topics:

  • Declaring a variable after accessing it from another class
  • Why Java does not support truly global variables
  • The reason a given code segment will not compile
  • Setting the proper value of a static variable grade

Skills Practiced

  • Making connections - understand why a piece of code will not compile
  • Knowledge application - use what you know to answer questions about why Java does not support truly global variables
  • Information recall - remember what you have learned about declaring a variable that originates in another class

Additional Learning

To discover more about Java, find the lesson titled Java Global Variable: Declaration & Examples. With this open, you can explore the additional content listed below:

  • Creating static variables
  • The 'final' modifier
  • Examples of code input with comments