5/13/2014
people do not wanted to make a copy */
1. Static variables first
variables in static method must not read and update instance variables*/
instance variable name, displays as null */
public class SimpleClass2 {
/*variables declared in the class but not in a method that have the
keyword static are called Static variables.*/ /*Static variables generally used for protection like database passwords, for this whichpeople do not wanted to make a copy */
/* class loader creates:
1. Static variables first
* 2. Loads static methods second
* 3. Creates instance variables
* 4. Loads instance methods Ex: File names, and make copies using objects
*/
private static int salary;
private static String name;
public static void main(String[] args) {
/*variables in static methods can only read
and update static variable. variables in static method must not read and update instance variables*/
SimpleClass2 sc2 = new SimpleClass2();
System.out.println(sc.name); /*wanted to check default value of
instance variable name, displays as null */
salary =30000; /*updating instance variable salary
name = "Jim";
System.out.println(name + " makes $ " + salary);
System.out.println(sc2.name);
}
No comments:
Post a Comment