Java - Class reference variable

Introduction

For the class of Employee

class Employee {
        String name;        // An instance variable
        String gender;      // An instance variable
        static long count;  // A class variable because of the static modifier
}

To declare a reference variable to store a reference of an instance of the Employee class.

Employee jack;

Employee is the class name, and jack is a variable of that type.

jack is a reference variable of Employee type.

jack variable can store a reference of an instance of the Employee class.

To store the reference returned by the new operator in a reference variable.

jack = new Employee();

You can also combine the above two statements into one.

Employee jack = new Employee();

Related Topic