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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 2341
Are you asking for an explanation or posing a challenge?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6588
    
    1

Hit me !


SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Anything wrong in this code ????
 
Similar Threads
interface
Instance variable access
What do "java gurus" understand form byte codes???
How to lookup Business Interface in EJB 3.0?
Thread output