Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

kevin goon
Ranch Hand
Posts: 62
int b1 = 1 << 31�� int b2 = 1 << 31 ; <br /> b1>>>= 31 ; b1>>>= 1 ;
b2>>= 31 ; b2>>= 1 ;
��A. b1 is all zero, b2 is all zero.
��B. b1 is all zero, b2 is all ones.
��C. b1 is all ones, b2 is all zero.
��D. b1 is all ones, b2 is all ones

Ans? b?
Q2)
I posted this one a while ago but no one answered yet, if anyone knows, pls, reply thank you
Can abstract method or class be static??
Also, Consider the following Thread coding1.public class SyncTest
2.private int x;
3.private int y;
4.private synchronized void set X (int i) x=i;
5.private synchronized void set y (int i) y=i;
6.public void setXY (int i) setX(i);set Y(i);
7.public synchronized boolean check() return x!=y;
8.
Under which conditions will check() return when called from a different class
A.check()can never return true
B.check() can return true when set XY is called by multiple treads
C.check() can true when multiple threads call set X and set Y separately
D.check() can only return true if synchTest is changed to allow x and y to be set separately

Dave Vick
Ranch Hand
Posts: 3244
Kevin
For Q1, answer B is correct:

int b1 = 1 << 31; int b2 = 1 << 31 ; <br /> b1>>>= 31 ; b1>>>= 1 ;
b2>>= 31 ; b2>>= 1 ;

after the 1st line both b1 and b2 are:
10000000 00000000 00000000 00000000
b1>>>=31 gives
00000000 00000000 00000000 00000001
b1>>>=1 gives
00000000 00000000 00000000 00000000
b2>>=31 gives
11111111 11111111 11111111 11111111
11111111 11111111 11111111 11111111
so B is correct.
hope that helps
Dave
[This message has been edited by Dave Vick (edited June 18, 2001).]

Manfred Leonhardt
Ranch Hand
Posts: 1492
Hi Kevin,
Can abstract method or class be static??
A static class (by definition in java only inner classes can be static) can be abstract. The following code shows that it will compile and run.

An abstract method can't be static for a simple reason. Abstract means that the method must be overridden, while static negates overridding (static methods can not be overridden, only hidden!).
Regards,
Manfred.

kevin goon
Ranch Hand
Posts: 62
Manfred,
Could explain in more detail what you mean by "hidden"?? You said->"static methods can not be overridden, only hidden!".
Does that mean once u override static method with another static method, the original method could never be reached(called)??
thank you

kevin goon
Ranch Hand
Posts: 62
Also,
Can anyone explain this problem??Q2)
I posted this one a while ago but no one answered yet, if anyone knows, pls, reply thank you
Can abstract method or class be static??
Also, Consider the following Thread coding1.public class SyncTest
2.private int x;
3.private int y;
4.private synchronized void set X (int i) x=i;
5.private synchronized void set y (int i) y=i;
6.public void setXY (int i) setX(i);set Y(i);
7.public synchronized boolean check() return x!=y;
8.
Under which conditions will check() return when called from a different class
A.check()can never return true
B.check() can return true when set XY is called by multiple treads
C.check() can true when multiple threads call set X and set Y separately
D.check() can only return true if synchTest is changed to allow x and y to be set separately

thanks!!!

Dave Vick
Ranch Hand
Posts: 3244
Kevin
What Manfred is saying is that when a method is static it is a class method. The method is called without any reference to a specific object. That means that the method to be called is determined at compile time, not at run time as with overriding.
check out this code here:

I call the static methods with object references to illustrate the point that they are not subject to late binding. The static methods called are determined by the type of the variable not by the type of the object it references. Unlike the nonstatic methods that are called based on the type of the object referenced.
hope that makes it a little clearer for you
Dave

Manfred Leonhardt
Ranch Hand
Posts: 1492
What Dave said ... he types faster than I do!
Manfred.

Dave Vick
Ranch Hand
Posts: 3244
Originally posted by Manfred Leonhardt:
What Dave said ... he types faster than I do!
Manfred.

Or, he has no life and spends much of his free time here, sucking all the knowledge around him. And occasionally letting a little slip back out.

Jyotsna Umesh
Ranch Hand
Posts: 94
Originally posted by Manfred Leonhardt:
Hi Kevin,
[b]Can abstract method or class be static??

A static class (by definition in java only inner classes can be static) can be abstract. The following code shows that it will compile and run.

An abstract method can't be static for a simple reason. Abstract means that the method must be overridden, while static negates overridding (static methods can not be overridden, only hidden!).
Regards,
Manfred.[/B]

But I had read somewhere "static methods can not be overridden to be non static, does it mean static methods can be overridden by static methods only?
Jyotsna

Dave Vick
Ranch Hand
Posts: 3244
Jyotsna
from the JLs section 8.4.6.2
If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class.

If you have a static metod in a class and then extend that class, the sub class can not have the same method unless it is also static. That method is considered hidden not overridden because it is subject to early binding, not late binding as in instance methods that are overridden.