Topic: 关于that

  Print this page

1.关于that Copy to clipboard
Posted by: 南夜星海
Posted on: 2005-09-11 13:24

请问java的关键字有“that”吗?它是派什么用处的?
Given:
1. public class X implements Runnable {
2. private int x;
3. private int y;
4.
5. public static void main(String [] args) {
6. X that = new X();
7. (new Thread( that )).start();//就是这个that我看不懂
8. (new Thread( that )).start();
9. }
10.
11. public void run() {
12. for (;;){
13. synchronized (this) {
14. x++;
15. y++;
16. }
17.
System.out.println(Thread.currentThread().getName() +
18. “x = “ + x + “, y = “ +
y);
19. }
20. }
21. }
What is the result?
A. Compilation fails.
B. The program prints pairs of values for x and y that might not always be the same on
the same line (for example, “x = 2, y = 1”).
C. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that both threads are executing
concurrently.
D. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that only a single thread is actually
executing.
Answer: D

2.Re:关于that [Re: 南夜星海] Copy to clipboard
Posted by: cjyzpcl
Posted on: 2005-09-11 19:30

没有 that

3.Re:关于that [Re: 南夜星海] Copy to clipboard
Posted by: why
Posted on: 2005-09-11 20:25

>> 6. X that = new X();
"that" is an instance of "X".

4.Re:关于that [Re: 南夜星海] Copy to clipboard
Posted by: 南夜星海
Posted on: 2005-09-11 23:21

汗,是我看题目不仔细........受教了

5.Re:关于that [Re: 南夜星海] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-09-12 00:33

Please check here before asking such a question! Thanks!

Java Language Keywords

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html

Here's a list of keywords in the Java language. These words are reserved — you cannot use any of these words as names in your programs. true, false, and null are not keywords but they are reserved words, so you cannot use them as names in your programs either.


abstract continue for new switch
assert *** default goto * package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum **** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp ** volatile
const * float native super while

* not used
** added in 1.2
*** added in 1.4
**** added in 5.0

6.Re:关于that [Re: 南夜星海] Copy to clipboard
Posted by: gavin_yue
Posted on: 2005-10-24 19:37

JAVA中 有this没有that

题中的只是一个变量名 随便起的~!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923