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 47
Ngày làm bài: Hôm nay lúc 18:51:13 (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 SyncTest 
{
    public static void main (String [] args) 
    {
        Thread t = new Thread() 
        {
            Foo f = new Foo();
            public void run() 
            {
                f.increase(20);
            }
        };
    t.start();
    }
}
class Foo 
{
    private int data = 23;
    public void increase(int amt) 
    {
        int x = data;
        data = x + amt;
    }
}
and assuming that data must be protected from corruption, what—if anything—can you add to the preceding code to ensure the integrity of data?
  A - 
Synchronize the run method.
  B - 
Wrap a synchronize(this) around the call to f.increase().
  C - 
The existing code will cause a runtime exception.
  D - 
Synchronize the increase() method
2-
What will be the output of the program?
class Test116 
{ 
static final StringBuffer sb1 = new StringBuffer(); 
static final StringBuffer sb2 = new StringBuffer(); 
public static void main(String args[]) 
{ 
    new Thread() 
    { 
        public void run() 
        { 
            synchronized(sb1) 
            { 
                sb1.append("A"); 
                sb2.append("B"); 
            } 
        } 
    }.start(); 

    new Thread() 
    { 
        public void run() 
        { 
            synchronized(sb1) 
            { 
                sb1.append("C"); 
                sb2.append("D"); 
            } 
        } 
    }.start(); /* Line 28 */

    System.out.println (sb1 + " " + sb2); 
    } 
}

  A - 
main() will finish before starting threads.
  B - 
main() will finish in the middle of one thread.
  C - 
main() will finish after one thread.
  D - 
Cannot be determined.
3-
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, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes execution.
4-
Which statement is true?
  A - 
Memory is reclaimed by calling Runtime.gc().
  B - 
Objects are not collected if they are accessible from live threads.
  C - 
An OutOfMemory error is only thrown if a single block of memory cannot be found that is large enough for a particular requirement.
  D - 
Objects that have finalize() methods always have their finalize() methods called before the program ends.
5-
What will be the output of the program (when you run with the -ea option) ?
public class Test 
{  
    public static void main(String[] args) 
    {
        int x = 0;  
        assert (x > 0) : "assertion failed"; /* Line 6 */
        System.out.println("finished"); 
    } 
}

  A - 
finished
  B - 
Compilation fails.
  C - 
An AssertionError is thrown.
  D - 
An AssertionError is thrown and finished is output.
6-
public class Test2 
{
    public static int x;
    public static int foo(int y) 
    {
        return y * 2;
    }
    public static void main(String [] args) 
    {
        int z = 5;
        assert z > 0; /* Line 11 */
        assert z > 2: foo(z); /* Line 12 */
        if ( z < 7 )
            assert z > 4; /* Line 14 */

        switch (z) 
        {
            case 4: System.out.println("4 ");
            case 5: System.out.println("5 ");
            default: assert z < 10;
        }

        if ( z < 10 )
            assert z > 4: z++; /* Line 22 */
        System.out.println(z);
    }
}
Which line is an example of an inappropriate use of assertions?
  A - 
Line 11
  B - 
Line 12
  C - 
Line 14
  D - 
Line 22
7-
Which statement is true?
  A - 
Assertions can be enabled or disabled on a class-by-class basis.
  B - 
Conditional compilation is used to allow tested classes to run at full speed.
  C - 
Assertions are appropriate for checking the validity of arguments in a method.
  D - 
The programmer can choose to execute a return statement or to throw an exception if an assertion fails.
8-
What will be the output of the program?
String x = "xyz";
x.toUpperCase(); /* Line 2 */
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);

  A - 
abcXyZ
  B - 
abcxyz
  C - 
xyzabc
  D - 
XyZabc
9-
What will be the output of the program?
class Tree { } 
class Pine extends Tree { } 
class Oak extends Tree { } 
public class Forest1 
{ 
    public static void main (String [] args)
    { 
        Tree tree = new Pine(); 
        if( tree instanceof Pine ) 
            System.out.println ("Pine"); 
        else if( tree instanceof Tree ) 
            System.out.println ("Tree"); 
        else if( tree instanceof Oak ) 
            System.out.println ( "Oak" ); 
        else 
            System.out.println ("Oops "); 
    } 
}

  A - 
Pine
  B - 
Tree
  C - 
Forest
  D - 
Oops
10-
What two statements are true about the result obtained from calling Math.random()?
  1. The result is less than 0.0.
  2. The result is greater than or equal to 0.0..
  3. The result is less than 1.0.
  4. The result is greater than 1.0.
  5. The result is greater than or equal to 1.0.
  A - 
1 and 2
  B - 
2 and 3
  C - 
3 and 4
  D - 
4 and 5
 
[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 ASP.NET (English) - Bài 08
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 20
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 48
Trắc nghiệm Linux - Bài 53
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 12
Trắc Nghiệm Java - Bài 08
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 86
Trắc Nghiệm ASP.NET - Bài 16
Trắc nghiệm Linux - Bài 64
Trắc Nghiệm C Sharp - Bài 15
Trắc Nghiệm Ngôn Ngữ Lập Trình C ( English ) - Bài 59
Trắc Nghiệm Ngôn Ngữ Lập Trình C - Bài 18
Trắc Nghiệm Thiết Kế Web (English) - Bài 30
Trắc nghiệm C++ - Bài 10
Trắc Nghiệm ASP.NET - Bài 22
Trắc Nghiệm C# - Bài 41
Trắc Nghiệm Java - Bài 53
Trắc Nghiệm Visual Basic - Bài 12
Trắc nghiệm Ngôn Ngữ Lập Trình C++ - Bài 04
Trắc Nghiệm ASP.NET - Bài 07
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