Son Le

Greenhorn
+ Follow
since Jan 15, 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
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Son Le

Achutha,
1.final int i = 100;
2.byte b = i;
3.System.out.println(b);
final keywords has an advantage that is the compiler can inline final elements. Line 2 will be treated like:
2.byte b=100;
Therefore, it's legal.
Hungson Le
Hi Manfred,
Thanks for your reply. I've been looking for more info about how certain Java API classes are implemented. I'd appreciate it if you can give me a link to those kinds of docs.
Thanks again,
Hungson Le
Hi
Rajani,
When you call the equals() method, you're actually calling the equals() method from class Object. You need to override this method then your code should be ok.
Here's an example:

Hungson Le
[This message has been edited by Son Le (edited January 24, 2001).]
[This message has been edited by Son Le (edited January 24, 2001).]
Chun,
The only reason I can think of is the difference in how Boolean and other wrapper classes are implemented.
Here you're comparing the handles (==) of the String returned from the toString method. I'd guess that because for the Boolean class, the only 2 values they can return are either "true" or "false", it doesn't need to create a new String when the toString method is called, while the other wrapper classes do.

Class Boolean is similar to class A in their toString() methods: return literal String that is placed in the string pool and reused later.
Please look at the code above and let me know if you think I'm right.
Hungson Le
[This message has been edited by Son Le (edited January 24, 2001).]
Shakti,
I'm getting what you expected.
I'm called.
z=10
I'm using Java1.2
Hungson Le
Kaustuv,
Objects reside in heap while primitive variables and references reside in stack.
Hungson Le
21 years ago
Cindy,
You're correct. I apologize for not reading the question carefully =).
Here's my correction.
class A{}
class Bextends A{}
class C extends B{}
class D extends A{}

A <-- B <-- C
^
|
D

X instanceof Y: return true when X is an instance of Y or a subclass of Y
1) obj instanceof B: not correct since an instance of C might satify this condition
2) obj instanceof A && !(obj instanceof C): not correct since an instance of A might satify this condition
3) obj instanceof B && !(obj instanceof C): correct since this is an instance of B and not an instance of subclass of B
4) !(obj instanceof c | | obj instanceof D): not correct since
obj can be an A,B, or any other classes
5) !(obj instanceof A) && !(obj instanceof C) && !(objinstanceof D): can be an instance of any other classes
HungSon Le

[This message has been edited by Son Le (edited January 18, 2001).]
Rishi,
We have the inheritance chain:
A <-- B <-- C <-- D
X instanceof Y: return true when X is an instance of Y or a subclass of Y
1) obj instanceof B: not correct since an instance of C or D might satify this condition
2) obj instanceof A && !(obj instanceof C): not correct since an instance of A might satify this condition
3) obj instanceof B && !(obj instanceof C): correct since this is an instance of B and not an instance of subclass of B
4) !(obj instanceof c | | obj instanceof D): not correct since
obj can be an A,B, or any other classes
5) !(obj instanceof A) && !(obj instanceof C) && !(objinstanceof D): can be an instance of any other classes
HungSon Le
Chaitali,
During the construction of an instance of B, exception is thrown from A() constructor. (B() construtor calls default constructor in A()) Since you don't specify the message, the default is null.
Try the following code for clarification

"OK" will print at the end.
SonLe
[This message has been edited by Son Le (edited January 17, 2001).]
[This message has been edited by Son Le (edited January 17, 2001).]
Rajneesh,
First thing, there's only pass by value in java.
I'll try to visualize the process
*sb1, sb2 are constructed:
sb1 --> "Hello"
sb2 --> "Hello"
*In method1(), since s1, s2 are copies of sb1, sb2, then
sb1 --> "Hello" <-- s1<br /> sb2 --> "Hello" <-- s2<br /> *s1.append("There")<br /> sb1 --> "HelloThere" <-- s1<br /> sb2 --> "Hello" <-- s2<br /> * s2 = s1;<br /> <br /> <br /> sb2 --> "Hello"
In main, sb1 --> "HelloThere"
sb2 --> "Hello"
Hope this'll help



[This message has been edited by Son Le (edited January 16, 2001).]
Hi,
The line: B bb=aa.new B();
should be: A.B bb=aa.new B();
A.B says that B is an inner class of A.

Hope this'll help
Zheng,
Remember arrays are also objects, so it's legal to do
array = (array) interface like you said since we can do
obj = (obj) interface
Hi,
I think "pal" is placed in the string pool. The operation s3 = s2 + "Pal" happens at runtime generating another string. The answer should be 3.
Please correct me if I'm wrong.
Hi,
Java operands are evaluated from left to right.
int k=a[b]=b = c=a[c] =1;
First, we'll have k, a[1], b,c, a[0]
Then assignments take place from right to left:
a[0]=1, c=1, b=1, a[1] =1, and k = 1
Hope this helps
21 years ago
Jini,
Remember that an array is also an object. The follow would be legal
interface A { ... }
class B implements A {...}
A a = new B();
B b = (B) a;
The most important thing to notice here is that the underlying object is an array, and object remembers its type.
Hope it'd help.