This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Just a basic question!" Watch "Just a basic question!" New topic

Just a basic question!

Maha Pratap

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();
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
You're correct the variable x is local to the constructor so it is not available outside of it.

It is sorta covered in the JavaRanch Style Guide.
subject: Just a basic question!
Similar Threads
casting between a ref type and an array.
enum question
Use of "this" keyword ?
extends Frame help
declaring constant variable in java