Lahcen Mannou

Greenhorn
+ Follow
since Oct 09, 2000
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 Lahcen Mannou

I passed today with a score of 93%.
I made some silly mistakes, in general I found the exam more easier than what I have expected.
There were only some though questions on threads, all the rest are not really hard.
Good luck to everybody !
18 years ago
Hi,
The expression "1 << 32" is equivalent to "1 << (32%32)",
so because 32%32 = 0, the result is 1.
Here is (I think ...) the explanation of your problem :
try this code, you will not get a compilation error any more :
public class A {
class B {} // note than static is removed.
}
class C extends A.B {
// Added code BEGIN
C(A a) {
a.super();
}
// Added code END
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
The problem is that the compiler tries to provide a default Constructor to your class C. The default constructor looks like that :
C() {
super();
}
But this default constructor will not works, because in order to get an instance of A.B, you have first to get an instance of A.
You must then provide an instance of A.
Lahcen.

Originally posted by Balamurugan Kandasamy:
The following compiles.
import java.lang.*;
public class A {
[b]static
class B {}
}
class C extends A.B {
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
But when I remove static for class B which is as below , it says
no enclosing instance of type A in scope.
import java.lang.*;

However if i dont extend A.B then it is not a problem.public class A {
class B {} // note than static is removed.
}
class C extends A.B {
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
import java.lang.*;
public class A {
static class B {}
}
class D {
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
Think im not clear in this funda. Pls throw some light.
Thanks
MKBala...[/B]


A VM exits also if all the remaining threads are DEAMON threads.
Ex. Say you created 2 user threads in your main() method, thread1 and thread2 and thread1 is a Deamon thread and thread 2 is not.
If the main thread finished (end of main() method), the VM continues to run.
Now if thread2 stopps the VM stopps immediatly without waiting for thread1 to stop (because it is a Deamon thread).
Hope I'm right.
Lahcen.

Originally posted by William Brogden:
The "main thread" is just the Thread used to execute the main method. It can easily start other threads and then die.
A Java application runs until either:
1) all user Threads are finished
2) The System.exit() method is called.
There is nothing magic about the "main" thread.
Bill



[This message has been edited by Lahcen Mannou (edited October 16, 2000).]
I think this "strange behaviour" may be explained like this :
When evaluationg the expression "i = i++", the following steps are performed :
1. first evalaute i++ expression. The result is 0.
2. then, (because the ++ operator has higher precedence than =),
increment i, so now i=1
3. finally affect the value of the expression (wich is 0)to i. i was 1 (after step 2), but now it becomes 0 !
I hope this explanation is OK. Any comment ?
Lahcen.
Hi,
Please can someone explain why a static variable is not permitted in a non-static inner class ?
Thanks in advance
Hi,
I think C and D are correct, according to the following rule :
"An instance of an inner class cannotbe created without first creating an instance of its outer class".
So,
A. is incorrect because there is no outer class ;
B. is incorrect for the same reason;
C. is correct because the new InnerClass is attached to the new OuterClass created just before
D. is correct because the new InnerClass object is attached to the object o
E. is incorrect because you cannot use "this" within a staic context (which is here the main() method)
Hope this will help.