• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheriting variables

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i in Pri hides i in Bases even though one 'i' is static and the other is not?
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic