theMatrix

Greenhorn
+ Follow
since Jun 15, 2001
Merit badge: grant badges
For More
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 theMatrix

Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?
1) Objects are deleted when they can no longer be accessed through any reference.
2) The finalize() method will eventually be called on every object.
3) The finalize() method will never be called more than once on an object.
4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.
5) The garbage collector will use a mark and sweep algorithm.
What's the difference between instance variable and class variable?
In java,the value returned by >>> will never be negative as long as the value of the right operand is equal to or greater than 1.
class Demo{
public static void main(String[] args){
(new SSC()).demo();
}
}
class C{
double value=300.00;
public double getvalue(){
System.out.println("C.value="+value);
return value;
}
}
class SC extends C{
double value=400.00;
public double getvalue(){
System.out.println("SC.value="+value);
return value;
}
}
class SSC extends SC{
double value=500.00;
public double getvalue(){
System.out.println("SSC.value="+value);
return value;
}
public void demo(){
getvalue();
((SC)this).getvalue();
((C)this).getvalue();
System.out.println();
System.out.println(value);
System.out.println(((SC)this).value);
System.out.println(((C)this).value);
}
}
the result is:
SSC.value=500.00
SSC.value=500.00
SSC.value=500.00
500.00
400.00
300.00
The reason is: method binds to a object at runntime
and variable binds depend on the object type at compiletime;
But i think just because of this reason,the answer is
SSC.value=500.00
SC.value=400.00
C.value=300.00
500.00
500.00
500.00
.
So what is the "(SC)this" really refers to at compiletime and runtime?
Is the result means that "(SC)this" acts at compiletime?
[This message has been edited by theMatrix (edited June 18, 2001).]