Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Just a basic question!  RSS feed

 
Maha Pratap
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maha
You're correct the variable x is local to the constructor so it is not available outside of it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!