1. Trang chủ
  2. » Công Nghệ Thông Tin

Đề thi lập trình java cuối kỳ

18 622 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 18
Dung lượng 423,93 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Đề thi trắc nghiệm lập trình java , đề thi cuối kỳ lập trình java, đề thi trắc nghiệm java, trắc nghiệm java bách khoa đà nẵng, bách khoa đà nẵng, đề thi bách khoa lập trình java, lập trình java cuối kỳ, mai văn hà

Trang 1

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

Lập trình Java giữa kỳ

Tổng số câu hỏi chính : 43

@media print { user_checked { border: 1px dashed gray; padding: 4px; } }

Câu hỏi 1: // filename Main.java

class Test {

protected int x, y;

}

 

class Main {

public static void main(String args[]) {

Test t = new Test();

System.out.println(t.x + " " + t.y);

}

}

Câu hỏi 2: class Test {

public static void main(String[] args) {

for ( int i = 0 ; 1 ; i++) {

System.out.println( "Hello" );

break ;

}

}

}

Câu hỏi 3: class Test {

public static void main(String[] args) {

for ( int i = 0 ; true ; i++) {

System.out.println( "Hello" );

A Compile Error

B Runtime error

C 0 0

D 1 1

A Compiler Error

B Runtime Error

C 1

D null

Trang 2

break ;

}

}

}

Câu hỏi 4: class Main {

public static void main(String args[]) {

System.out.println(fun());

}

int fun() {

return 20 ;

}

}

Câu hỏi 5: class Main {

public static void main(String args[]) {

System.out.println(fun());

}

static int fun() {

return 20 ;

}

}

A Compiler Error

B Runtime Error

C Hello

D Hello Hello Hello

A Compiler Error

B Runtime Error

C 20

D 0

A Compiler Error

B Runtime Error

C 20

D 0

Trang 3

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

Câu hỏi 6: class Test {

public static void main(String args[]) {

System.out.println(fun());

}

static int fun() {

static int x= 0 ;

return ++x;

}

}

Câu hỏi 7: class Test { 

private static int x; 

public static void main(String args[]) { 

    System.out.println(fun()); 

static int fun() { 

    return ++x; 

 

Câu hỏi 8: class Test {

int x = 10 ;

public static void main(String[] args) {

Test t = new Test();

System.out.println(t.x);

}

}

A Compiler Error

B Runtime Error

C 1

D 0

A Compiler Error

B Runtime Error

C 1

D 0

A Compiler Error

B Runtime Error

C 10

Trang 4

Câu hỏi 9: // filename: Test.java 

class Test {     

    int y = 2; 

    int x = y+2; 

    public static void main(String[] args) {     

        Test m = new Test(); 

        System.out.println("x = " + m.x + ", y = " + m.y); 

    } 

 

Câu hỏi 10: // filename: Test.java 

public class Test 

{     

    int x = 2; 

    Test(int i) { x = i; } 

    public static void main(String[] args) {     

        Test t = new Test(5); 

        System.out.println("x = " + t.x); 

    } 

 

Câu hỏi 11: // Main.java 

public class Main 

    public static void gfg(String s) 

    {     

        System.out.println("String"); 

    } 

D 0

A Compiler Error

B Runtime Error

C x = 4, y = 2

D x = 2, y = 2

A Compiler Error

B Runtime Error

C x = 5

D x = 2

Trang 5

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

    public static void gfg(Object o) 

    { 

        System.out.println("Object"); 

    } 

    public static void main(String args[]) 

    { 

        gfg(null); 

    } 

} //end class 

 

Câu hỏi 12: // Main.java 

public class Main 

    public static void gfg(String s) 

    {     

        System.out.println("String"); 

    } 

    public static void gfg(Object o) 

    { 

        System.out.println("Object"); 

    } 

    public static void gfg(Integer i) 

    { 

        System.out.println("Integer"); 

    } 

    public static void main(String args[]) 

    { 

        gfg(null); 

    } 

} //end class 

 

A Compiler Error

B Runtime Error

C String

D Object

E null

A Compiler Error

B Runtime Error

C String

D Object

Trang 6

Câu hỏi 13: // Main.java 

public class Main 

    public static void main(String args[]) 

    { 

        short s = 0; 

        int x = 07; 

        int y = 08; 

        int z = 112345; 

        s += z; 

        System.out.println("" + x + y + s); 

    } 

} //end class 

 

Câu hỏi 14: class GfG 

    public static void main(String args[]) 

    { 

        String s1 = new String("geeksforgeeks"); 

        String s2 = new String("geeksforgeeks"); 

        if (s1 == s2) 

            System.out.println("Equal"); 

        else

            System.out.println("Not equal"); 

    } 

 

E Integer

A Compiler Error

B Runtime Error

C 07 08 0

D 7 8 0

A Compiler Error

B Runtime Error

C Equal

D Not equal

Trang 7

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

Câu hỏi 15: class Gfg 

    // constructor 

    Gfg() 

    { 

        System.out.println("Geeksforgeeks"); 

    } 

    

    static Gfg a = new Gfg(); //line 8 

    public static void main(String args[]) 

    { 

        Gfg b; //line 12 

        b = new Gfg(); 

    } 

 

Câu hỏi 16: class Test { 

    int a = 10; 

    static int b = 20; 

public

    static void main(String[] args) 

    { 

        Test t1 = new Test(); 

        t1.a = 100; 

        t1.b = 200; 

        Test t2 = new Test(); 

        System.out.println("t1.a =" + t1.a + " t1.b =" + t1.b); 

        System.out.println("t2.a =" + t2.a + " t2.b =" + t2.b); 

    } 

A Compiler Error

B Runtime Error

C Geeksforgeeks

D Geeksforgeeks Geeksforgeeks

A t1.a=100 t1.b=200 t2.a=10 t2.b=200

B t1.a=10 t1.b=200 t2.a=10 t2.b=200

C t1.a=100 t1.b=200 t2.a=10 t2.b=20

D t1.a=100 t1.b=200 t2.a=100 t2.b=200

Trang 8

Câu hỏi 17: class Test2 { 

public

    static void main(String[] args) 

    { 

        byte x = 12; 

        byte y = 13; 

        byte result = x + y; 

        System.out.print(result); 

    } 

 

Câu hỏi 18: class Test3 { 

public

    static void main(String[] args) 

    { 

        int x = 011; 

        int y = 0xfee; 

        int result = x + y; 

        System.out.print(x + ":" + y + ":" + result); 

    } 

 

Câu hỏi 19: class Test4 { 

public

    static void main(String[] args) 

    { 

        int x = 0198; 

        int y = 0xfree; 

        int result = x + y; 

        System.out.print(x + " : " + y + " : " + result); 

A 25

B Error

C -25

D none

A Error

B 010 : 0xfee : 4089

C 9 : 4078 : 4087

D 010 : 0xfee : 4087

Trang 9

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

    } 

 

Câu hỏi 20: class Test5 { 

public

    static void main(String[] args) 

    { 

        final int a = 1, b = 5; 

        for (int i = 0; a < b; i++) { 

            System.out.println("Hello"); 

        } 

        System.out.println("Hi"); 

    } 

 

Câu hỏi 21: import java.util.*; 

public class Test { 

public static void main(String[] args) 

    { 

        int[] x = { 120, 200, 016 }; 

        for (int i = 0; i < x.length; i++) 

            System.out.print(x[i] + " "); 

    } 

 

A Error

B 0198 : 0xfree : 68734

C 144 : 68590 : 68734

D 0198 :68590 : 68788

A Hello Hello … … …

B Error

C Hello Hello Hello Hello Hello

D Hello Hello Hello Hello Hello Hi

A 120 200 16

B 120 200 14

C 120 200 016

Trang 10

Câu hỏi 22: import java.util.*; 

public class Test { 

public static void main(String args[]) 

    { 

        String S1 = "S1 =" + "123" + "456"; 

        String S2 = "S2 =" + (123 + 456); 

        System.out.println(S1); 

        System.out.println(S2); 

    } 

 

Câu hỏi 23: import java.util.*; 

public class Test { 

public static void main(String[] args) 

    { 

        int[] x = { 1, 2, 3, 4 }; 

        int[] y = x; 

        x = new int[2]; 

        for (int i = 0; i < x.length; i++) 

            System.out.print(y[i] + " "); 

    } 

 

D 016 is a compile error It should be written as 16

A S1=123456, S2=579

B S1=123456, S2=123456

C S1=579, S2=579

D None of This

A 1 2 3 4

B 0 0 0 0

C 1 2

D 0 0

Trang 11

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

Câu hỏi 24: class selection_statements { 

    public static void main(String args[]) 

    { 

        int var1 = 5; 

        int var2 = 6; 

        if ((var2 = 1) == var1) 

            System.out.print(var2); 

        else

            System.out.print(++var2); 

    } 

 

Câu hỏi 25: class comma_operator { 

    public static void main(String args[]) 

    { 

        int sum = 0; 

        for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1) 

            sum += i; 

        System.out.println(sum); 

    } 

 

Câu hỏi 26: class BitShi { 

    public static void main(String[] args) 

    { 

        int x = 0x80000000; 

        System.out.print(x + " and "); 

        x = x >>> 31; 

        System.out.println(x); 

    } 

 

A 5

B 6

C 14

D comilation error

A -2147483648 and 1

B 0x80000000 and 0x00000001

Trang 12

Câu hỏi 27: class Test1 { 

public

    static void main(String[] args) 

    { 

        int String = 65; 

        int Runnable = 97; 

        System.out.print(String + " : " + Runnable); 

    } 

 

Câu hỏi 28: class Test2 { 

public

    static void main(String[] args) 

    { 

        int if = 65; 

        int else = 97; 

        System.out.println(if + " : " + else); 

    } 

 

Câu hỏi 29: class Test3 { 

public

    static void main(String[] args) 

    { 

        int x = 1; 

        if (x) { 

            System.out.print("GeeksForGeeks"); 

C -2147483648 and -1

D 1 and -2147483648

A Error

B a

C 65:97

D None

Trang 13

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

        } else { 

            System.out.print("GFG"); 

        } 

    } 

 

Câu hỏi 30: class Test4 { 

public

    static void main(String[] args) 

    { 

        double d1 = 123.456; 

        double d2 = 12_3.4_5_6; 

        double d3 = 12_3.4_56; 

        System.out.println(d1); 

        System.out.println(d2); 

        System.out.println(d3); 

    } 

 

Câu hỏi 31: public class Prg { 

    public static void main(String args[]) 

    { 

        System.out.print('A' + 'B'); 

    } 

 

A GeeksForGeeks

B GFG

C Error

D None

A Error

B 123.456 12_3.4_5_6 12_3.4_56

C 123.456 123.456 123.456

D None

A AB

B 195

C 131

Trang 14

Câu hỏi 32: public class Prg { 

    public static void main(String args[]) 

    { 

        System.out.print("A" + "B" + 'A' + 10); 

    } 

 

Câu hỏi 33: public

class Prg { 

    public static void main(String args[]) 

    { 

        System.out.print(20 + 1.34f + "A" + "B"); 

    } 

 

Câu hỏi 34: public

class Test { 

public

    static void main(String[] args) 

    { 

        int b = 2147483648; 

        System.out.println(b); 

    } 

 

D Error

A ABA10

B AB65

C Error

D AB

A 201.34AB

B 201.34fAB

C 21.34AB

D Error

A No output

Trang 15

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

Câu hỏi 35: public class Test 

    static char ch = 59; 

    public static void main(String[] args) 

    { 

        System.out.println(ch); 

    } 

 

Câu hỏi 36: public

class Test { 

public

    static void main(String[] args) 

    { 

        int x = 0xGeeks; 

        System.out.println(x); 

    } 

 

Câu hỏi 37: public

class Test { 

public

    static void main(String[] args) 

    { 

B 2147483648

C 2147483647

D compile-time error

A compile-time error

B null

C No output

D ;

A 1

B Compile-time error

C null

D Run-time error

Trang 16

        // we are assiging 8 byte data to 4 byte variable 

        float f = 10l; 

        System.out.println(f); 

    } 

 

Câu hỏi 38: class ArrayDemo { 

public static void main(String[] args) 

    { 

        int arr1[] = { 1, 2, 3, 4, 5 }; 

        int arr2[5] = { 1, 2, 3, 4, 5 }; 

        for (int i = 0; i < 5; i++) 

            System.out.print(arr1[i] + " "); 

        System.out.println(); 

        for (int i = 0; i < 5; i++) 

            System.out.print(arr2[i] + " "); 

    } 

 

Câu hỏi 39: class ArrayDemo1 { 

public static void main(String[] args) 

    { 

        int arr1[] = new int[0]; 

        int arr2[] = new int[-1]; 

        System.out.print(arr1.length + " : " + arr2.length); 

    } 

 

A 1 2 3 4 5 \n 1 2 3 4 5

B 1 2 3 4 5 \n 1 2 3 4

C Error

A 0 : 0

B 0 : -1

C Compiler Error

Trang 17

2/11/2020 Luyện thi hướng đối tượng C++ - Quản lý site - Trắc nghiệm

Câu hỏi 40: class ArrayDemo1 { 

public static void main(String[] args) 

    { 

        int arr1[] = new int[2147483647]; 

        int arr2[] = new int[2147483648]; 

        System.out.println(arr1.length); 

        System.out.println(arr2.length); 

    } 

 

Câu hỏi 41: class ArrayDemo1 { 

public static void main(String[] args) 

    { 

        short s = 45; 

        int arr1[] = new int[s]; 

        char ch = 'A'; 

        int arr2[] = new int[ch]; 

        long l = 10; 

        int arr3[] = new int[l]; 

        System.out.println(arr1.length); 

        System.out.println(arr2.length); 

        System.out.println(arr3.length); 

    } 

 

Câu hỏi 42: kết quả: u=4; y=5; u = 6, t =7, z;

t -=u+++ y;

t+=++u + y;

z = u+++v++

D Run-time error

A 45 65 10

B 45 A 10

C Error

Trang 18

© Luyện thi hướng đối tượng C++ xuanmanhitweb1011@gmail.com

URL đến bài thi này: http://testhdtc.aztest.vn/tin-hoc/lap-trinh-java-giua-ky-56.html

Câu hỏi 43:         String java = "Java", ja = "Ja", va = "va";

        System.out.println(java == "Ja"+"va");

        System.out.println(java == "Ja"+va);

        System.out.println(java == ja+va);

A true false false

B false true false

C false true true

Ngày đăng: 02/11/2020, 23:56

TỪ KHÓA LIÊN QUAN

w