From: Ged Byrne Date: 2003-08-22T07:08:40+09:00 Subject: Re: Class variables - a surprising result My earlier post showed that Java's static variables behave exactly the same way. The only difference is that Java offers a few more choices: - Make the variable private so that it isn't inherited. - Override the variable in an ancestor by DECLARING it afresh. However, you still have to be careful because any inherited methods will refer to the Static variable in the base class. --- Michael Campbell wrote: > > > As far as I know, C++ and Java do not have class > variables. They have > > > static member variables, > > > > .. . . which are not inherited, which is why it is > surprising to many > > that Ruby's @@variables are inherited. > > > What do you mean by "not inherited"... I'm sure > you're correct, but I'm > confused: > > C:\tmp>cat Sub.java > > class Base { > static int B = 1; > } > > public class Sub extends Base { > public static void main(String[] args) { > System.out.println("Sub.B = " + Sub.B); > } > } > > > C:\tmp>javac Sub.java > > C:\tmp>java Sub > > Sub.B = 1 > > ________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://uk.messenger.yahoo.com/