Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes var access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "var access" Watch "var access" New topic
Author

var access

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
I would like to know that why the var str has the value "Super" and not "Sub".

output : Super
When the var str is also in test why isn't the test's copy of str is being used in R's showvar.
Rajeshwari Natarajan
Ranch Hand

Joined: Mar 05, 2003
Posts: 67
2 reasons...
(1) In test, str is a local variable inside main method
(2) showvar() is not overriden by test.
If u want "Sub" to be printed, then this should be the code.


regards<br />Rajeshwari. N
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Anupam
In this case, the variable str in main method can not access to the class R, because the str in main method belong to main method only.
So, the class R use own variable str as the print result when invoked the default constructor super() in the constructor test.
In you want print "Sub"

If it is not clear,please post again.


Francis Siu
SCJP, MCDBA
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Sub variable is local to main. Unless it is passed as an argument to showvar it is not visible within such method.


SCJP2. Please Indent your code using UBB Code
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Well what I think is that code would be replaced by the method that showvar() method. I think I am wrong but can you actually tell me if this happens or not.
 
 
subject: var access
 
Similar Threads
About StackOverflowError
Problem regarding oops concept
overridden method output
Construtor Doubt
need help