Class type members in Java
Forums:
class Config {
//type constant
static final int maxConnections = 3;
//type fields
static public String host;
static public int port;
//type method
static public String GetConnection() {
return String.format("%s:%s", host, port);
}
//type initializer
static {
host = "10.0.0.1";
}
}
Config.port = 52;
String connection = Config.GetConnection();
//connection is "10.0.0.1:52"
Config.host = "10.0.0.3";
connection = Config.GetConnection();
//connection is "10.0.0.3:52"
- Log in to post comments