Simon Whitehouse

Greenhorn
+ Follow
since Dec 10, 2001
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Simon Whitehouse

Hi Rajinder
Our query is not with string immutability but with the fact that one thread may interrupt the other one in between the two System.out.println statements. Because of that we think that it is not possible to determine what the screen output will be.
So our query hinges on threads and not Strings.
All the best
Simon
Hi Salamina
Well I'd put d. for the same reason, fwiw.
This is not the only time that I have found myself puzzling over a question when I think that one option is not exactly right and there is an answer of None of the above or similar.
All the best
Simon
I was expecting this code to throw an ArrayIndexOutOfBounds exception at the line
a[i]=i=9;
It's my understanding that the assignment operator takes precedence from the right and that would make that line the same as
a[i]=(i=9);
And so that would end up with us trying to assign the integer value 9 to a[9].
I realise that there is either a flaw in my logic or a gap in my knowledge and quite probably both. Could somebody tell me what it is please?
Cheers
Simon
Okay then. Thanks to everybody who has posted replies so far. I've had a look at a couple of other threads and I think that I'm finally getting somewhere.
I think that if, instead of line 11 in the code that I originally quoted, I replaced it with :-

Then the code would compile although I'm a bit hazy as to exactly why.
I'm getting very confused about the idea that the subclass can only access superclass variables in this example if they create and use that superclass member themselves.
My problem is exacerbated because I can't get the code to compile. I have separated the two files, saved them to my Java directory on the hard drive and compiled superclassX.java. When I try to compile subclassY then the compiler complains that it can't find packageX in the import statement and that it can't find superclassX.
Any further help much appreciated.
Finding this bit dog-darn difficult and looking forward to a yee-ha moment soon ......
Simon
Hi there
Is this the sort of thing that you meant :-

It's not pretty but it works for me.
<Edited as I realised you wanted to include the spaces in the command line as well>
hth
Simon
[ January 15, 2002: Message edited by: Simon Whitehouse ]
Hi Folks
The following is from JWhiz, test 1 Q3

Answers given are:
A. Compilation error at line 9
B. Compilation error at line 5
C. Runtime error at line 11
D. None of the above.
The answer is given as D as there will be a compilation error at line 11 as objX is not allowed to access any protected member of the SuperclassX.
Now, what has me baffled is that protected members " .. are accessible....by all subclasses of this class in any package where this class is visible." (from KM). The more that I look at this the more my head spins, can somebody please explain it to me?
Cheers
Simon
I'm not sure that your conclusions are correct. As I understand it the same thing is happening - the next line is subject to the preceding construct and the third line is always executed once that has been done.
To clarify this you might like to ensure that the value of z is greater than 5. The following line will not be executed but the one after it will.
hth
Simon
Hi Sudha
On my machine I get the output " defabc" - note the blank space is also in there from the initialization.
BUT, a HashSet is a non-ordered set and so it is not surprising that different systems give different outputs. If you change the set from a HashSet to a TreeSet (which is an ordered set) then you will get the output that you were expecting.
I'm sure that there is more to be said about this but I hope the above helps
All the best
Simon
Hi Folks
Can somebody explain to me why the setSize() at //1 appears to have no effect on the Frame that is produced by this code. I think that it is setting the size because if I add the line
System.out.println(this.getSize());
after //1 then it prints out the dimensions that I am trying to set it to. But the frame produced is miniscule

Thanks
Simon
Hi Patrick
I also got the message that the variable age may not have been initialized. There was no class file generated though and I interprete that as meaning it did not compile.
I can't think of an instance when I have ever had a compile time error and yet had the code compile. I assume that the two are mutually exclusive and that the question is checking our knowledge of that.
hth
Simon
Hi Wei Liu
Q1 Yes, you can declare variable identifiers starting with initial upper case letters. Both double and byte are keywords but as Java is case sensitive Byte and Double are not.
Q2. The question is really testing how well we understand how primitives are promoted when they are used in numeric operations. The convention is that both operands are promoted to int, unless one of them is broader than an int in which case the narrower operand is promoted to that.
So, in this case both operands are bytes so they are both promoted to ints and then multiplied giving an int value of 120. This is then assigned to a variable identifier Integer which is declared to be a byte and the compiler complains at this.
In order to get the code to compile then either Integer should be declared to be an int or the result of the multiplication of Byte and Double needs to be cast to a byte.
That's how I understand it anyway.
hth
Simon
Hi Rashmi
notify() and notifyAll() are used after a thread has executed some synchronized code in order to allow waiting threads to take their turn at executing that code.
So, a thread must be running when it calls notify() and there is nothing in the call which will cause the thread to halt its flow of execution.
hth
Simon