wood burning stoves*
The moose likes Java in General and the fly likes Just a basic question! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Just a basic question!" Watch "Just a basic question!" New topic
Author

Just a basic question!

Maha Pratap
Greenhorn

Joined: Jun 18, 2002
Posts: 4
Hey all,
I really have a basic question which can be best described as shown below:-
public class SomeClass{

public SomeClass(){
int x =20;
}
public static void main(String[] args){
SomeClass y = new SomeClass();
System.out.println(y.x);
}
this will give me compile error right. Is it because the variable "x" does not belong to class and when we try to access the variable , it comaplains? or ... I know this is a real basic question but just want to clear my fundas ... thanks..
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Maha
You're correct the variable x is local to the constructor so it is not available outside of it.


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Just a basic question!