Tìm kiếm:
TRANG NHÀ
Giới thiệu VNEDU.ORG
Điều khoản và bản quyền
Liên lạc VNEDU
TRẮC NGHIỆM TRỰC TUYẾN
---Công Cụ:---
Soạn Biểu thức
Bảng màu HTML
Ký hiệu đặc biệt 01
Ký hiệu đặc biệt 02
Ký hiệu đặc biệt 03
Ký hiệu đặc biệt 04
Ký hiệu đặc biệt 05
Ký hiệu đặc biệt 06
Ký hiệu đặc biệt 07
Ký hiệu đặc biệt [Toán]
Tin Học   ||  Căn Bản    Văn Phòng    Hệ Thống - Mạng    Phần Mềm Ứng Dụng    Kỹ thuật số    Lập trình    SQL  

Trắc Nghiệm Java - Bài 28
Ngày làm bài: Hôm nay lúc 23:11:00 (Server time)
Số câu hỏi: 10.   Tổng điểm: 10
Yêu cầu hoàn thành: 60 phút.
Thời gian còn lại: 
Cỡ chữ câu hỏi:  Cỡ chữ đáp án:


1-
What will be the output of the program?
public class Test107 implements Runnable 
{ 
    private int x; 
    private int y; 

    public static void main(String args[]) 
    {
        Test107 that = new Test107(); 
        (new Thread(that)).start(); 
        (new Thread(that)).start(); 
    } 
    public synchronized void run() 
    {
        for(int i = 0; i < 10; i++) 
        { 
            x++; 
            y++; 
            System.out.println("x = " + x + ", y = " + y); /* Line 17 */
        } 
    } 
} 

  A - 
Compilation error.
  B - 
Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... but the output will be produced by both threads running simultaneously.
  C - 
Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... but the output will be produced by first one thread then the other. This is guaranteed by the synchronised code.
  D - 
Will print in this order x = 1 y = 2 x = 3 y = 4 x = 5 y = 6 x = 7 y = 8...
2-
What will be the output of the program?
public class Test 
{
    public static void main (String [] args) 
    {
        final Foo f = new Foo();
        Thread t = new Thread(new Runnable() 
        {
            public void run() 
            {
                f.doStuff();
            }
        });
        Thread g = new Thread() 
        {
            public void run() 
            {
                f.doStuff();
            }
        };
        t.start();
        g.start();
    }
}
class Foo 
{
    int x = 5;
    public void doStuff() 
    {
        if (x < 10) 
        {
            // nothing to do
            try 
            {
                wait();
                } catch(InterruptedException ex) { }
        } 
        else 
        {
            System.out.println("x is " + x++);
            if (x >= 10) 
            {
                notify();
            }
        }
    }
}

  A - 
The code will not compile because of an error on notify(); of class Foo.
  B - 
The code will not compile because of some other error in class Test.
  C - 
An exception occurs at runtime.
  D - 
It prints "x is 5 x is 6".
3-
What will be the output of the program?
class MyThread extends Thread 
{
    public static void main(String [] args) 
    {
        MyThread t = new MyThread();
        Thread x = new Thread(t);
        x.start(); /* Line 7 */
    }
    public void run() 
    {
        for(int i = 0; i < 3; ++i) 
        {
            System.out.print(i + "..");
        }
    }
}

  A - 
Compilation fails.
  B - 
1..2..3..
  C - 
0..1..2..3..
  D - 
0..1..2..
4-
Which statement is true?
  A - 
A static method cannot be synchronized.
  B - 
If a class has synchronized code, multiple threads can still access the nonsynchronized code.
  C - 
Variables can be protected from concurrent access problems by marking them with the synchronized keyword.
  D - 
When a thread sleeps, it releases its locks.
5-
Which two can be used to create a new Thread?
  1. Extend java.lang.Thread and override the run() method.
  2. Extend java.lang.Runnable and override the start() method.
  3. Implement java.lang.Thread and implement the run() method.
  4. Implement java.lang.Runnable and implement the run() method.
  5. Implement java.lang.Thread and implement the start() method.
  A - 
1 and 2
  B - 
2 and 3
  C - 
1 and 4
  D - 
3 and 4
6-
Which statement is true?
  A - 
If only one thread is blocked in the wait method of an object, and another thread executes the modify on that same object, then the first thread immediately resumes execution.
  B - 
If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.
  C - 
If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call.
  D - 
If two threads are blocked in the wait method of one object, then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call.
7-
Which two statements are true?
  1. Deadlock will not occur if wait()/notify() is used
  2. A thread will resume execution as soon as its sleep duration expires.
  3. Synchronization can prevent two objects from being accessed by the same thread.
  4. The wait() method is overloaded to accept a duration.
  5. The notify() method is overloaded to accept a duration.
  6. Both wait() and notify() must be called from a synchronized context.
  A - 
1 and 2
  B - 
3 and 5
  C - 
4 and 6
  D - 
1 and 3
8-
The following block of code creates a Thread using a Runnable target:
Runnable target = new MyRunnable();
Thread myThread = new Thread(target);
Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
  A - 
public class MyRunnable extends Runnable{public void run(){}}
  B - 
public class MyRunnable extends Object{public void run(){}}
  C - 
public class MyRunnable implements Runnable{public void run(){}}
  D - 
public class MyRunnable implements Runnable{void run(){}}
9-
Which statement is true?
  A - 
The notifyAll() method must be called from a synchronized context.
  B - 
To call wait(), an object must own the lock on the thread.
  C - 
The notify() method is defined in class java.lang.Thread.
  D - 
The notify() method causes a thread to immediately release its locks.
10-
void start() {  
    A a = new A(); 
    B b = new B(); 
    a.s(b);  
    b = null; /* Line 5 */
    a = null;  /* Line 6 */
    System.out.println("start completed"); /* Line 7 */
} 
When is the B object, created in line 3, eligible for garbage collection?
  A - 
after line 5
  B - 
after line 6
  C - 
after line 7
  D - 
There is no way to be absolutely certain.
 
[Người đăng: Thành Lãm - ST]
Ghé thăm Kênh của Vị Sư "hai lần chết đi sống lại"
Tu Si Chau Soc Thon

https://www.youtube.com/channel/UCoyC9WTTVR-M3qpTKKEXGnQ

Chau Soc Thon Official Channel


Phong Bảo Official
Phong Bao Official
Xem Nhiều nhất
Trắc Nghiệm Pascal - Bài 20
Trắc Nghiệm ASP.NET - Bài 12
Trắc Nghiệm Ngôn Ngữ Lập Trình C - Bài 16
Trắc Nghiệm ASP.NET - Bài 01
Trắc Nghiệm ASP.NET - Bài 03
Trắc nghiệm C++ - Bài 18
Trắc Nghiệm C# - Bài 53
Trắc Nghiệm ASP.NET - Bài 02
Trắc Nghiệm C# - Bài 42
Trắc Nghiệm Java - Bài 01
Trắc Nghiệm ASP.NET - Bài 04
Trắc Nghiệm Pascal - Bài 22
Trắc Nghiệm ASP.NET - Bài 13
Trắc Nghiệm ASP.NET - Bài 09
Trắc Nghiệm ASP.NET - Bài 08
Trắc nghiệm PHP - Bài 01
Trắc Nghiệm ASP.NET - Bài 06
Trắc Nghiệm ASP.NET - Bài 11
Trắc Nghiệm ASP.NET - Bài 05
Trắc Nghiệm ASP.NET - Bài 23
Đề Xuất
Trắc Nghiệm Thiết Kế Web Và Flash - Bài 07
Trắc Nghiệm C Sharp - Bài 11
Trắc Nghiệm Visual Basic - Bài 21
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 42
Trắc Nghiệm Thiết Kế Web (English) - Bài 49
Trắc Nghiệm ASP.NET (English) - Bài 14
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 08
Trắc nghiệm Ngôn Ngữ Lập Trình C++ - Bài 02
Trắc Nghiệm ASP.NET (English) - Bài 28
Trắc nghiệm Linux ( English ) - Bài 30
Trắc Nghiệm Visual Foxpro - Bài 09
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 78
Trắc Nghiệm Java - Bài 08
Trắc Nghiệm Thiết Kế Web Và Flash - Bài 33
Trắc nghiệm Ngôn Ngữ Lập Trình C++ - Bài 16
Trắc Nghiệm C Sharp - Bài 06
Trắc Nghiệm ASP.NET - Bài 02
Trắc nghiệm Ngôn Ngữ Lập Trình C++ - Bài 01
Trắc nghiệm XML - Bài 14
Trắc nghiệm Linux - Bài 54
Phát triển hệ thống: TRƯƠNG HỮU ĐỨC - Phiên bản 3.0 - © Copyright 2013 - 2024 - VNEDU.ORG

free counters