View Single Post
  #1 (permalink)  
Old 11-07-2007, 02:41 PM
ravian ravian is offline
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
accessing instance variables from static methods
Please review the code below:

Code:
public class CarClass { public String carName; public static void main(String[] args) { carName = "Mazda"; // cannot access static member here } public void setterMethod() { carName = "Mazda"; // works fine } }
Main is a static method and I want to access a non static variable (instance variable) called carName in main method. What is the best way of doing that?

Thanks.
Reply With Quote
Sponsored Links