CodePudding user response:
You are right that, strictly speaking, in the above example, we are declaring variables alex, linda, john that will hold reference to an object.
But since they hold reference to an object, in a juggling of terminologies, we can call them objects.
So a variable can be considered a syntactic construct, while the object (what it refers to) is its semantic.
It's like in Math, you can say sin(x) is a function, but strictly speaking it is an expression. To be a function you also have to specify its domain, so sin(x) in this case is refering to the function x -> sin(x) where x is a real number.
CodePudding user response:
Employee is a class
alex is an object of the class Employee
alex is an instance of the class Employee
alex for the jvm is the variable of object that doesn't contains the object data.
alex is said to be an instance of Employee and an Employee object for simplicity.
In Java, no variable can ever hold an object.
A variable can only hold a reference to an object [1].
Instead of holding an object itself, a variable holds the information necessary to find the object in memory. This information is called a reference or pointer to the object [1].
Object is not stored in the variable.The object is somewhere else; the variable points to it [1].
[1] https://math.hws.edu/javanotes/c5/s1.html