Board index » jbuilder » static

static


2003-07-16 04:39:11 PM
jbuilder22
I have static variable and static method in my base class:
public abstract class MailBase {
protected static Connection con;
public static boolean openDBConnection(String cDriverClass, String
cConnectionString) {
...
return true;
}
public static boolean closeDBConnection() throws Exception {
...
return true;
}
}
Can I use those methods/variable in child classes? I'd like to have this
variable separated for every child class. This would be possible (default
behavior) if variable would not be static, but I am not sure for "static"
variables:
public class MailBody extends MailBase {
private static Connection con;
public MailBody() {
}
}
And:
public class MailSubject extends MailBase {
private static Connection con;
public MailBody() {
}
}
Now I can call:
MailBody.openDBConnection();
MailSubject.openDBConnection();
MailBody mb = new MailBody();
MailSubject ms = new MailSubject();
And both classes would have different con values, no matter that con
variable is "static"?
 
 

Re:static

Well, the question is: are static variables derived just like ordinary
variables? I mean: does every child class have it's own "static" variable or
it is common for parent and child class (if you set "static" variable in
child class, it will also set the same value for derived class)?