• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bit shift, thread q's

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Correct answer(s)??

 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
b2>>=1 gives the same answer
11111111 11111111 11111111 11111111
so B is correct.
hope that helps
Dave
[This message has been edited by Dave Vick (edited June 18, 2001).]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kevin,
Dave has already verified your Q1 answer, so ...
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for reply=)
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Correct answer(s)??

thanks!!!
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Dave said ... he types faster than I do!
Manfred.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manfred Leonhardt:
Hi Kevin,
Dave has already verified your Q1 answer, so ...
[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?
Please Clarify.
Thanks in advance
Jyotsna
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
I hope that answers your question, if not let me know...
Dave
 
reply
    Bookmark Topic Watch Topic
  • New Topic