aspose file tools*
The moose likes Java in General and the fly likes Anything wrong in this code ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Anything wrong in this code ????" Watch "Anything wrong in this code ????" New topic
Author

Anything wrong in this code ????

sekhar subbu
Greenhorn

Joined: Nov 21, 2006
Posts: 7
public class Person
{
int i=9 ;
{

int i=10 ;

}

public static void main(String args[])
{
int u=90;
{

int u=190;

}

}

}
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Are you asking for an explanation or posing a challenge?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Hit me !


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Murad Iqbal
Ranch Hand

Joined: Dec 09, 2003
Posts: 90
It will not compile. Try changing

int u=190;

to

int j=190;


and it would work just fine. Previous declaration of int i would not be seen as a duplicate as they are in separate blocks of code, thus their scope is limited to their blocks. The repitition of
u
in main is not allowed however.
sekhar subbu
Greenhorn

Joined: Nov 21, 2006
Posts: 7
Originally posted by Murad Iqbal:
It will not compile. Try changing

in main is not allowed however.


Hi
thanks a lot for the explanation....actually i saw it in a java test question paper and i was wondering abt the answer?

anyways now i got the answer .

But i wanted to know why does in main ....we cant have that redeclaration like in class ?
Murad Iqbal
Ranch Hand

Joined: Dec 09, 2003
Posts: 90
Its not about main. Its about method. You can not have that redeclared in a method. In a class you can.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anything wrong in this code ????