The type of variable programmer is Employee. Because the variables are bound at compile time, the type of the object that's referenced by the variable emp doesn't make a difference. programmer.name will access the variable name defined in the class Employee.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
the type of the object that's referenced by the variable emp doesn't make a difference
pagano monello wrote:
Also, why the author says:
the type of the object that's referenced by the variable emp doesn't make a difference
I do cannot understand the sense of this observation.
the type of the object that's referenced by the variable emp doesn't make a difference
pagano monello wrote:Hi Paul,
thank you for you answer. You are totally right!!!
In effect I am still confused about the meaning of the term "binding"; I guess that it could stand for "decide", "establish", "determine", but I am not sure at all.
Also, why the author says:
the type of the object that's referenced by the variable emp doesn't make a difference
I do cannot understand the sense of this observation.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
When you use type of parent, even if you use object of children when you try access variable, you will get variable from type reference of which you use
In case of variables, static methods, and private instance methods, this decision is made by the compiler. Why? Nothing special here. It is a rule of Java language. The compiler will decide which member will be used by an expression. The JVM simply uses that particular member as per compiler's decision. How does the compiler decide? Compiler has no knowledge about the actual objects referred to by a variable, right? (Because actual objects are created by by the JVM at run time.) Compiler does have an fair idea but it doesn't know that for sure. So obviously, it cannot decide based on the object type. All it is left with is the variable type.
pagano monello wrote:Ah wow, I re-read slowly this piece of post:
In case of variables, static methods, and private instance methods, this decision is made by the compiler. Why? Nothing special here. It is a rule of Java language. The compiler will decide which member will be used by an expression. The JVM simply uses that particular member as per compiler's decision. How does the compiler decide? Compiler has no knowledge about the actual objects referred to by a variable, right? (Because actual objects are created by by the JVM at run time.) Compiler does have an fair idea but it doesn't know that for sure. So obviously, it cannot decide based on the object type. All it is left with is the variable type.
So I may have understood: in this case, the type of the variable programmer.name is decided by the compiler; anyway the compiler doesn't know which is the actual object, then it lets the variable type.
Thank you, really.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I am a man of mystery. Mostly because of this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|