5/13/2014
/*variables declared in the class but not in a method that do not have the
keyword static are called instance variables*/
private int salary; /*instance variable - declared in class and outside of a method , and with no keyword - static
public static void main(String[] args) {
SimpleClass sc = new SimpleClass(); /*object sc is created, blue print of class
}
public class SimpleClass {
/*variables declared in the class but not in a method that do not have the
keyword static are called instance variables*/
private int salary; /*instance variable - declared in class and outside of a method , and with no keyword - static
private String name; /*instance variable
public static void main(String[] args) {
/* sc points at instance variable */
SimpleClass sc = new SimpleClass(); /*object sc is created, blue print of class
sc.salary =30000; /*at object, variable salary has value 300000
sc.name = "Jim"; /*at object, variable name has valu Jim
System.out.println(sc.name + "makes $" + sc.salary);
}
Why instance variables are declared private or they have to be private or what?
ReplyDeleteAre instance variables and methods different from class methods and variables?
ReplyDelete