View Single Post
  #5 (permalink)  
Old 11-07-2007, 08:10 PM
hardwired's Avatar
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Code:
public class CarClass {
    public String carName;

    public static void main(String[] args) {
        // Create instance of enclosing class and save it in
        // a reference, viz, the local variable "carClass".
        CarClass carClass = new CarClass();
        // Use this instance variable to access
        // the member variable "carName".
        carClass.carName = "Mazda";
        //carName = "Mazda";
        // cannot access static member here
    }

    public void setterMethod() {
        carName = "Mazda";
        // works fine
    }
}
Reply With Quote