File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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
 
jQuery in Action, 2nd edition
 
subject: Just a basic question!
 
Similar Threads
extends Frame help
declaring constant variable in java
casting between a ref type and an array.
Use of "this" keyword ?
enum question