Originally posted by Greg Georges:
Can someone please explain the logic of this question, cannot seem to grasp the idea
What will be the result of attempting to compile and run the following program?
class TestClass
{
public static void main(String args[])
{
boolean b = false;
int i = 1;
do
{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
The answer is that it will print 3.
Guess that (b = !b) evaluates to (false = true), so therefore we go through another iteration because the condition is true, then I suppose it becomes (true = false) and exit the loop. Is this the correct reasoning?
Originally posted by James Du:
Hi Lam, thanks for reply
I think in a arithmetic sense, it's imposible for a type of 64bits to distinguish more than 2^64 distinct numbers, they have just 2^64 different combinations! how does it accomplish that?
Originally posted by James Du:
Hi,
We know that type long has 64bits, so the the amount of the distinct numbers it can hold is 2 to the power of 64.
My puzzle is: since type double has the same number of bits, why it could hold the number greater than long both in precision and in magnitude? How many numbers could it distinguish?
Originally posted by devesh singh:
#) lass wrapper
{
public static void main(String [] str)
{
static int l; // 1
Integer I = new Integer(6);
System.out.println(I);
System.out.println(l);
}
}
what is wrong withh this code if i removw line 1 then its all OK
Originally posted by Shah Chunky:
Dear Lam...
Throwable is A Class & Not an Interface
So what do u think the answer would be ?
Thanks
Originally posted by Shah Chunky:
Dear Friends.
My Question Still remains ?
What i want to know from u guys is that what will be the answer for both the Questions ?
For Q.1) should i choose (b) i.e. Throwable
(Remember Exception is super class of all Exceptions)
Q.2) Should i choose False.
Thanks
Originally posted by jeena jose:
can some one expain to me:
we can't declare a trasient variabe inside a final or static method.why???
Originally posted by Hima Mangal:
hi all..
pls have a look at the following code..
What will this program print out ?
class Base{
int value = 0;
Base(){
addValue();
}
void addValue(){
value += 10;
}
int getValue(){
return value;
}
}
class Derived extends Base{
Derived(){
addValue();
}
void addValue(){
value += 20;
}
}
public class Test {
public static void main(String[] args){
Base b = new Derived();
System.out.println(b.getValue());
}
}
1. 10
2. 20
3. 30
4. 40
the correct answer is 40.. how is this so.. shouldn't the method in the base class constructor call its own addValue() method??
also, if the methods are declared static, the output is 30.. aren't static methods resolved by the type or reference and not by the type of object??
Thanx in advance..
Originally posted by Cindy Glass:
Here is my password. Make sure that is can not be serialized. Make sure that it can not be changed.
transient final
Originally posted by James Du:
I think static instances and final instances were implicitly transient, you needn't specify them at all.
serialization is for object, not for class, so what's the meaning of serialize the static instances of a object? how do you deserialize them? restore them to the Class object?
serializatioin is for transfering object data. final instances means instances that can not be changed, then what's the use to serialize them and deserialize them since 2 sides of the transfer both knows what's the very value of the instance?
any comments?
Regards,
James
Originally posted by Ravindra Mohan:
Hi Folks,
Lam has correcly understood the point made by Cindy..
Ravindra Mohan.
[This message has been edited by Ravindra Mohan (edited May 13, 2001).]
Originally posted by Ravindra Mohan:
Hi Lam,
You have correctly answered the question.
Good explanation.
Ravindra Mohan
Originally posted by Yuki Cho:
The following code prints out 3. I thought it will go in an infinite loop since it is while (true), but it is not. Please explain... thanx!!!
-----------
What will be the result of attempting to compile and run the following program?
class TestClass
{
public static void main(String args[])
{
boolean b = false;
int i = 1;
do
{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
Originally posted by Yuki Cho:
hi there,
can you please explain to me why the following code doesn't compile? i thought class B is able to access class A since B extends A even though they are in different package.
--------
//in file A.java
package p1;
public class A
{
protected int i =10;
public int getI() {return i;}
}
//in file B.java
package p2;
import p1.*;
public class B extends p1.A
{
public void process(A a)
{
a.i = a.i*2;
}
public static void main(String args[])
{
A a = new B();
B b = new B();
b.process(a);
System.out.println(a.getI());
}
}
thanks,
yuki
6.6.2.1 Access to a protected Member
Let C be the class in which a protected member m is declared. Access is permitted only within the body of a subclass S of C. In addition, if Id denotes an instance field or instance method, then:
If the access is by a qualified name Q.Id, where Q is an ExpressionName, then the access is permitted if and only if the type of the expression Q is S or a subclass of S.