1. Technology
Send to a Friend via Email




Scope refers to the lifetime and accessibility of a variable. How large the scope is depends on where a variable is declared. For example, if a variable is declared at the top of a class then it will accessible to all of the class methods. If it’s declared in a method then it can only be used in that method.

For more information, have a look at the Understanding Variable Scope and Using Modifiers With Variables.


For example, the scope of the variable NUMBER_OF_HOURS_IN_A_DAY is the whole class. Whereas the scope of NUMBER_OF_DAYS_IN_A_WEEK is just the calculateHoursInWeeks method:

public class AllAboutHours{
   private final int NUMBER_OF_HOURS_IN_A_DAY = 24;

   public int calculateHoursInDays(int days)
     return days * NUMBER_OF_HOURS_IN_A_DAY;

   public int calculateHoursInWeeks(int weeks)
      final int NUMBER_OF_DAYS_IN_A_WEEK = 7;


# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  1. About.com
  2. Technology
  3. Java
  4. Java Glossary
  5. S
  6. Scope - Definition for the Java Term

©2014 About.com. All rights reserved.