aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inheriting variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inheriting variables" Watch "inheriting variables" New topic
Author

inheriting variables

marilyn murphy
Ranch Hand

Joined: Aug 28, 2001
Posts: 84

Since this code will not compile if the line marked "line 1" is not commented out due to "i is already defined in Pri", why don't we get the same compile error due to the i Pri inherited from Base?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello Marilyn,
There are no errors because the 'i' in the class 'Pri' hides the 'i' in the class 'Base'. If you don't want this you can change the name of the variable to something else. Also I just modified your code. Have a look.

HIH
---------------------------------------------------------

[This message has been edited by chandrashekar munukutla (edited October 24, 2001).]
marilyn murphy
Ranch Hand

Joined: Aug 28, 2001
Posts: 84
So i in Pri hides i in Bases even though one 'i' is static and the other is not?
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
I think yes.. as both have same identifier. yes but static var can be access by class name also and can be used in static methods.
CMIW
even static methods are not overridden but they are hide.

------------------
Regards
Ravish


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Gurpreet Sachdeva
Ranch Hand

Joined: Feb 20, 2001
Posts: 90
Hello Marilyn,
That is true that i in Pri will hide i in Base even if one is static and other is not. But you need to comment Line 1, as you already had one variable named i in the current scope. You can't declare two variable with the same name in the same scope.

------------------
Regards
Gurpreet Sachdeva
For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: http://www.go4java.lookscool.com


Regards<BR>Gurpreet Sachdeva<P>For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: <A HREF="http://www.go4java.lookscool.com" TARGET=_blank rel="nofollow">http://www.go4java.lookscool.com</A>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheriting variables