Sun certified programmer developer for java 2 study guide phần 9

Chọn tất cả các câu trả lời chính xác cho mỗi câu hỏi. Hãy dành thời gian của bố, nếu được đặt trong một lớp học khác hơn MyOuter hoặc MyInner instantiates một thể hiện của lớp lồng nhau?Bạn phải có một tham chiếu đến một thể hiện của lớp kèm theo để khởi tạo nó. B. Nó không có quyền truy cập vào | 60 Chapter 9 Threads SELF TEST ANSWERS 1. 0 C. Line 5 calls the run method so the run method executes as a normal method should. s A is incorrect because line 4 is the proper way to create an object. B is incorrect because it is legal to call the run method even though this will not start a true thread of execution. The code after line 5 will not execute until the run method is complete. D is incorrect because the for loop only does two iterations. E is incorrect because the program runs without exception. 2. 0 A and D. Only start and run are defined by the Thread class. s B and C are incorrect because they are methods of the Object class. E is incorrect because there s no such method in any thread-related class. 3. 0 C. The class correctly implements the Runnable interface with a legal public void run method. s A is incorrect because interfaces are not extended they are implemented. B is incorrect because even though the class would compile and it has a valid public void run method it does not implement the Runnable interface so the compiler would complain when creating a Thread with an instance of it. D is incorrect because the run method must be public. E is incorrect because the method to implement is run not start . 4. 0 B. When the start method is attempted a second time on a single Thread object the method will throw an IllegalThreadStateException you will not need to know this exception name for the exam . Even if the thread has finished running it is still illegal to call start again. s A is incorrect because compilation will succeed. For the most part the Java compiler only checks for illegal syntax rather than class-specific logic. C and D are incorrect because of the logic explained above. 5. 0 C. Because the class implements Runnable an instance of it has to be passed to the Thread constructor and then the instance of the Thread has to be started. s A is incorrect. There is no constructor like this for Runnable because Runnable is an interface and it .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.