abi hari

Greenhorn
+ Follow
since Jan 23, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by abi hari

class setTest{
static int s1;
int ii=0;

public static void main(String[] args){
setTest st = new setTest();
st.m1(1);
}
void m1(int x){
m2(x);
}
void m2(int x){
s1=x;
}
}

My question is: is there a compile time problem only if non-static variable is accessed from static context. Wouldn't accesing a static variable from a non-static context pose any problem? Like here, method m2(int x) is assigning to a static variable s1.

Thanks to explain me why this is so.
thanks kenny & marc. got it :-)
hi,

i came across this question on one of the sites.

public class ifTest{

public static void main(String[] args){
boolean b = false;
String s = null;
s=(b=!b)?(b=!b)?"Hello":"hello" b=!b)?"world":"World";
System.out.println(s);
}
}

what is the result?

The answer comes as "hello". But i never knew this conditional statement could be written like this. I thought, it was a if <condition1>?then1:else1.But this seems a little complex to bring under this syntax. Can anyone tell me how to decipher this statement?

Thanks in advance.
Hi,

I see this question in the self-test of K&B.

class cardBoard{
Short story = 5;
cardBoard go(cardBoard cb){
cb=null;
return cb;
}

public static void main(String[] args){
cardBoard c1= new cardBoard();
cardBoard c2 = new cardBoard();
cardBoard c3 = c1.go(c2);
c1=null;
// do stuff
}
}

The question is, when //doStuff is reached how many objects are eligible for garbage collection?
a.0
b.1
c.2
d.compilation fails
e.it is not possible to know
f.runtime exception

In this case, won't we take c1, c3, cb as objects that can be garbage collected. The answer says c.2 is correct and the explanation says c1 and the associated Short wrapper object are eligible for GC.

I don't understand how to identify objects for GC. Thanks to let me know the same.

Best Regards,
Abirami
hi keith,

what does it mean by 'referring to the variable by its simple name'? if this is the case, then in what kind of situation does varible shadowing occur?

Thanks in advance.