SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
JDBCSupport - An easy to use, light-weight JDBC framework -
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Cameron Wallace McKenzie wrote:
Variables don't get overridden, they get 'shadowed.' It's the shadowing that is causing confusion.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Cameron Wallace McKenzie wrote:See!!! It's even confusing me!
Two variables that are part of the same class with the same variable name is confusing, regardless of which label gets affixed to it.
-Cameron McKenzie
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Jesper Young wrote:The 'this' reference in line 13 refers to the same object that 'c' refers to in lines 6 and 7.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Lukas Smith wrote:
Jesper Young wrote:The 'this' reference in line 13 refers to the same object that 'c' refers to in lines 6 and 7.
So why does it print 0 instead of 10? The visible x is that contains the value of 10. The x from tree is hidden.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Lukas Smith wrote:So there should be:
"The keyword "this" always, always, always refers to the object currently running when polymorphism works."
Am I wrong?
SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Ninad Kulkarni wrote:
Here the nearest scope of x is tree class not cast class. Java choose always nearest scope.
Correct me if I am wrong.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Ninad Kulkarni wrote:
Here the nearest scope of x is tree class not cast class. Java choose always nearest scope.
Correct me if I am wrong.
The x variable (of the cast class) is *not* in scope to the get() method.
SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions