What is the use of a private static variable in Java? -
If a variable is It is declaring that In both cases it can not be accessed as All can be accessed as For example: You make it public static varName; , then I can access it from anywhere
ClassName.varName . I also know that stable members are shared with all instances of a class and are not re-specified in each instance.
private static varName; a variable
private varName; ?
ClassName.varName or
ClassInstance.varName < P>
ClassName.var_name , but only from within the class that it has been defined - because it is
private < / Code> is
public static or
private constant variable is often used for constants, for example, many people In the code "defeat E-codes do not like "constant; They want to make a
public stable or
private static variable with a meaningful name and use it in their code, to make the code more readable. (You can also create such a constant
final ).
Example of public class {Private final static string JDBC_URL = "jdbc: mysql: // local host / shopdb"; Personal Final Static String JDBC_USERNAME = "User Name"; Personal Final Static String JDBC_PASSWORD = "Password"; Public static zero main (string [] args) {connection conn = DriverManager.getConnection (JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD); // ...}}
public or
personal , depending on whether you want it That they appear outside the variable class or not.
Comments
Post a Comment