天启黑马信息科技(北京)有限公司 后端开发工程师 笔试题

感谢您能抽出几分钟时间来参加本次答题,现在我们就马上开始吧!
姓名
    ____________
手机
    ____________
邮箱
    ____________
boss上显示的名称
    ____________
package testpkg.p1;

public class ParentUtil

{

    public int x = 420;

    protected int doStuff() { return x; }

}

package testpkg.p2;

import testpkg.p1.ParentUtil;

public class ChildUtil extends ParentUtil

{

    public static void main(String [] args)

    {

        new ChildUtil().callStuff();

    }

    void callStuff()

    {

        System.out.print("this " + this.doStuff() ); /* Line 18 */

        ParentUtil p = new ParentUtil();

        System.out.print(" parent " + p.doStuff() ); /* Line 20 */

    }

}

下列说法正确的是:

A.程序输出 this 420 parent 420.
B.18行代码错误
C.20行代码错误
D.程序会抛出异常
哪个集合类允许扩大或缩小其大小,并提供对其元素的索引访问,但其方法不是同步的(synchronized)?
A.java.util.HashSet
B.java.util.LinkedHashSet
C.java.util.List
D.java.util.ArrayList
哪种方法不会直接导致线程停止
A.notify()
B.wait()
C. InputStream access
D. sleep()
class X implements Runnable

{

    public static void main(String args[])

    {

        /* Missing code? */

    }

    public void run() {}

}

下列哪种方法可以启动线程?

A.Thread t = new Thread(X);
B. Thread t = new Thread(X); t.start();
C. X run = new X(); Thread t = new Thread(run); t.start();
D. Thread t = new Thread(); x.run();
哪三个保证一个线程会离开运行状态

yield()

wait()

notify()

notifyAll()

sleep(1000)

aLiveThread.join()

Thread.killThread()

A.1, 2 and 4
B. 2, 5 and 6
C. 3, 4 and 7
D. 4, 5 and 7

int i = l, j = -1;

switch (i)

{

    case 0, 1: j = 1; /* Line 4 */

    case 2: j = 2;

    default: j = 0;

}

System.out.println("j = " + j);

程序的输出是?

A.j = -1
B. j = 0
C. j = 1
D. 编译错误
public class SwitchTest

{

    public static void main(String[] args)

    {

        System.out.println("value =" + switchIt(4));

    }

    public static int switchIt(int x)

    {

        int j = 1;

        switch (x)

        {

            case l: j++;

            case 2: j++;

            case 3: j++;

            case 4: j++;

            case 5: j++;

            default: j++;

            }

        return j + x;

    }

}

程序的输出是?

A.value = 2
B. value = 4
C. value = 6
D. value = 8
关于java.util.HashSet下列说法正确的是?
A.集合中的元素是有序的。
B. 集合保证是不可变的。
C.集合中的元素保证是唯一的。
D.使用唯一键访问集合中的元素。
public class RTExcept

{

    public static void throwit ()

    {

        System.out.print("throwit ");

        throw new RuntimeException();

    }

    public static void main(String [] args)

    {

        try

        {

            System.out.print("hello ");

            throwit();

        }

        catch (Exception re )

        {

            System.out.print("caught ");

        }

        finally

        {

            System.out.print("finally ");

        }

        System.out.println("after ");

    }

}

程序的输出是?

A.hello throwit caught
B. 编译错误
C. hello throwit RuntimeException caught after
D. hello throwit caught finally after
class A

{

    public A(int x){}

}

class B extends A { }

public class test

{

    public static void main (String args [])

    {

        A a = new B();

        System.out.println("complete");

    }

}

程序的输出是?

A.无输出
B. 编译正常,运行报错
C. 编译错误
D. complete
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
public class StringRef

{

    public static void main(String [] args)

    {

        String s1 = "abc";

        String s2 = "def";

        String s3 = s2; /* Line 7 */

        s2 = "ghi";

        System.out.println(s1 + s2 + s3);

    }

}

程序的输出是?

A.abcdefghi
B. abcdefdef
C. abcghidef
D. abcghighi
public void foo( boolean a, boolean b)

{

    if( a )

    {

        System.out.println("A"); /* Line 5 */

    }

    else if(a && b) /* Line 7 */

    {

        System.out.println( "A && B");

    }

    else /* Line 11 */

    {

        if ( !b )

        {

            System.out.println( "notB") ;

        }

        else

        {

            System.out.println( "ELSE" ) ;

        }

    }

}

A.如果 a 为真且 b 为真,则输出为“A B”
B.如果 a 为真且 b 为假,则输出为“notB”
C.如果 a 为假且 b 为真,则输出为“ELSE”
D.如果 a 为假且 b 为假,则输出为“ELSE”
class Bitwise

{

    public static void main(String [] args)

    {

        int x = 11 & 9;

        int y = x ^ 3;

        System.out.println( y | 12 );

    }

}

程序的输出是?

A.0
B. 7
C. 8
D. 14
public class X

{

    public static void main(String [] args)

    {

        String names [] = new String[5];

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

            names[x] = args[x];

        System.out.println(names[2]);

    }

}

运行如下命令:java X a b

程序的输出是?

A.names
B. null
C. 编译错误
D. 运行时抛异常
您希望一个类可以访问同一个包中另一个类的成员。 实现这一目标的最严格的访问是什么?
A.public
B. private
C. protected
D. default access
程序的输出是?

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.编译错误
B. 以如下顺序打印: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... 但输出将由同时运行的两个线程产生.
C. 以如下顺序打印: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... 但输出将由第一个线程产生,然后由另一个线程产生。 这是由同步代码保证的。
D. 以如下顺序打印: x = 1 y = 2 x = 3 y = 4 x = 5 y = 6 x = 7 y = 8...
下列说法正确的是
A.有时明确抛出 AssertionError 是一种很好的做法。
B. 私有 getter() 和 setter() 方法不应使用断言来验证参数。
C. 如果在 try-catch 块中抛出 AssertionError,finally 块将被绕过。
D. 使用 catch (AssertionException ae) 块处理断言语句失败是正确的。
下列说法正确的是
A.调用 Runtime.gc() 将导致符合条件的对象被垃圾回收。
B.垃圾收集器使用标记和清除算法。
C. 如果一个对象可以从一个活动线程中访问,它就不能被垃圾回收。
D. 如果对象 1 引用对象 2,则对象 2 不能被垃圾回收。
public class Test

{

    public void foo()

    {

        assert false; /* Line 5 */

        assert false; /* Line 6 */

    }

    public void bar()

    {

        while(true)

        {

            assert false; /* Line 12 */

        }

        assert false; /* Line 14 */

    }

}

哪一个会导致编译失败

A.Line 5
B. Line 6
C. Line 12
D. Line 14
请用java实现一个函数。输入是一个数组,数组的元素都是数字,里面的数字有重复出现的。函数返回一个新的数组,是对输入数组去重的结果
    ____________

25题 | 被引用0次

使用此模板创建