Types of Variables: Part 1

Learn about the different types of variables with the help of examples in this lesson.

Reference variables

Now, we can give a summary of a few key rules about variables. We have found three types of variables so far:

  1. Reference variable
  2. Local variable
  3. Instance variable

The reference variables are directly related to the object scope. We have seen some problems and studied their nature through those problems.

Local variables

Local variables have some special characteristics. They are declared within a block, or method, or constructor. When the method is called, or the block is entered, these local variables are created and destroyed when we leave the block or if the call is returned from the method. We cannot access these variables outside this block of code. Furthermore, we have to initialize local variables.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy