打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
龙通科技招聘笔试题A(Java方向)

龙通科技招聘笔试题(Java方向)

考试说明:

1. 总分:100分;考试时间:100分钟

2.选择题为不定项选择,不全对没分,2分/总分40分;

3、请将答案写在答题纸上

一、选择题:(40分)

Question 1

1. public interface Status {

2. /* insert code here */ int MY_VALUE = 10;

3. }

Which three are valid on line 2?

A. final  B. static  C. native  D. public  E. private  F. abstract   G. protected

Question 2

1. public class Bar {                                                 3. // insert code here

2.static void foo(int...x) {                                        4. } }

Which two code fragments, inserted independently at line 3, will allow the class to compile?

A. foreach(x) System.out.println(z);                             B. for(int z : x) System.out.println(z);

C.while(x.hasNext())System.out.println(x.next());     D.for( inti=0;i<x.length;i++ )system.out.println(x[i]);<="" span="">

Question 3

31. // some code here                                        35. // some code here

32. try {                                                                36. } finally {

33. // some code here                                        37. // some code here

34. } catch (SomeException se) {                        38. }

Under which three circumstances will the code on line 37 be executed?

(Choose three.)

A. The instance gets garbage collected.                        B. The code on line 33 throws an exception.

C. The code on line 35 throws an exception.                D. The code on line 31 throws an exception.

E. The code on line 33 executes successfully.

Question 4

Assume that country is set for each class.

10. public class Money {

11. private String country, name;

12. public getCountry() { return country; }

13.}

and:

24. class Yen extends Money {

25. public String getCountry() { return super.country; }

26. }

27.

28. class Euro extends Money {

29. public String getCountry(String timeZone) {

30. return super.getCountry();

31. }

32. }

Which two are correct? (Choose two.)

A. Yen returns correct values.                                        B. Euro returns correct values.

C. An exception is thrown at runtime.                                D. Yen and Euro both return correct values.

E. Compilation fails because of an error at line 25.        F. Compilation fails because of an error at line 30.

Question 5

10. class Nav{

11. public enum Direction { NORTH, SOUTH, EAST, WEST }

12. }

13. public class Sprite{

14. // insert code here

15. }

Which code, inserted at line 14, allows the Sprite class to compile?

A. Direction d = NORTH;                                B. Nav.Direction d = NORTH;

C. Direction d = Direction.NORTH;                D. Nav.Direction d = Nav.Direction.NORTH;

Question 6

10. interface Foo { int bar(); }                                                14. fubar(

11. public class Sprite {                                                        15. // insert code here

12. public int fubar( Foo foo) { return foo.bar(); }                        16.);

13. public void testFoo() {                                                        17.}}

Which code, inserted at line 15, allows the class Sprite to compile?

A. Foo { public int bar() { return 1; } }                        B. new Foo { public int bar() { return 1; } }

C. newFoo() { public int bar(){return 1; } }                D. new class Foo { public int bar() { return 1; } }

Question 7

1. class TestA {

2. public void start() { System.out.println(”TestA”); }

3. }

4. public class TestB extends TestA {

5. public void start() { System.out.println(”TestB”); }

6. public static void main(String[] args) {

7. ((TestA)new TestB()).start();

8. }

9. }

What is the result?

A. TestA                                                B. TestB

C. Compilation fails.                                D. An exception is thrown at runtime.

Question 8

11. public abstract class Shape {                                16. this.x = x;

12. int x;                                                                        17. this.y = y;

13. int y;                                                                        18. }

14. public abstract void draw();                                        19. }

15. public void setAnchor(int x, int y) {

and a class Circle that extends and fully implements the Shape class.

Which is correct?

A.        Shape s = new Shape();                                        B.        Circle c = new Shape();

s.setAnchor(10,10);                                                        c.setAnchor(10,10);

s.draw();                                                                        c.draw();

C.         Shape s = new Circle();                                        D.        Shape s = new Circle();

s.setAnchor(10,10);                                                        s->setAnchor(10,10);

s.draw();                                                                        s->draw();

E.         Circle c = new Circle();

c.Shape.setAnchor(10,10);

c.Shape.draw();

Question 9

1. public class GoTest {

2. public static void main(String[] args) {

3. Sente a = new Sente(); a.go();

4. Goban b = new Goban(); b.go();

5. Stone c = new Stone(); c.go();

6. }

7. }

8.

9. class Sente implements Go {

10. public void go() { System.out.println(”go in Sente.”); }

11. }

12.

13. class Goban extends Sente {

14. public void go() { System.out.println(”go in Goban”); }

15. }

16.

17. class Stone extends Goban implements Go { }

18.

19. interface Go { public void go(); }

What is the result?

A. go in Goban                                        B.         go in Sente

go in Sente                                                go in Sente

go in Sente                                                go in Goban

C.         go in Sente                                        D.         go in Goban

go in Goban                                                go in Goban

go in Goban                                                go in Sente

E.         Compilation fails because of an error in line 17.

Question 10

11. public static void parse(String str) {                        17. System.out.println(f);

12. try {                                                                        18. }

13. float f= Float.parseFloat(str);                                19. }

14. } catch (NumberFormatException nfe) {                20. public static void main(String[] args) {

15. f= 0;                                                                        21. parse(”invalid”);

16. } finally {                                                                22. }

What is the result?

A. 0.0                                        C. A ParseException is thrown by the parse method at runtime

B. Compilation fails.                        D. A NumberFormatException is thrown by the parse method at runtime.

Question 11

35. String #name = “Jane Doe”;                        37. Double_height = 123.5;

36.int$age=24;                                                38. double~temp = 37.5;

Which two are true? (Choose two.)

A. Line 35 will not compile.                B. Line 36 will not compile.

C. Line 37 will not compile.                D. Line 38 will not compile.

Question 12

11. public class Ball {                                                                14. // insert code here

12. public enum Color { RED, GREEN, BLUE };                        15. { System.out.println(c); }

13. public void foo() {                                                        16. }}

Which code inserted at line 14 causes the foo method to print RED,GREEN, and BLUE?

A. for( Color c : Color.values())                        B. for( Color c = RED; c <= BLUE; c++)

C. for( Color c; c.hasNext() ; c.next())        D. for( Color c = Color[0]; c <= Color[2]; c++)

E. for( Color c = Color.RED; c <= Color.BLUE; c++)

Question 13

A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways:

logIt(”log message 1 “);

logIt(”log message2”,”log message3”);

logIt(”log message4”, “log message5”, “log message6);

Which declaration satisfies this requirement?

A. public void logIt(String * msgs)                B. public void logIt(String [] msgs)

C. public void logIt(String... msgs)                D. public void logIt(String msg1, String msg2, String msg3)

Question 14

A JavaBeans component has the following field:

11. private boolean enabled;

Which two pairs of method declarations follow the JavaBeans standard for accessing this field? (Choose two.)

A.         public void setEnabled( boolean enabled)                B.        public void setEnabled( boolean enabled)

public boolean getEnabled()                                        public void isEnabled()

C.         public void setEnabled( boolean enabled)                D.        public boolean setEnabled( boolean enabled)

public boolean isEnabled()                                        public boolean getEnabled()

Question 15

10. class One {                                                                14. public One foo() { return this; }

11. public One foo() { return this; }                                15. }

12. }                                                                                16. class Three extends Two {

13. class Two extends One {                                        17. // insert method here}

Which two methods, inserted individually, correctly complete the Three class? (Choose two.)

A. public void foo() { }                        B. public int foo() { return 3; }

C. public Two foo() { return this; }        D. public One foo() { return this; }

E. public Object foo() { return this; }

Question 16

11. class Person {                                                        19. }

12. String name = “No name’;                                        20.

13. public Person(String nm) { name = nm; }                21. public class EmployeeTest {

14. }                                                                                22. public static void main(String[] args) {

15.                                                                                23. Employee e = new Employee(”4321”);

16. class Employee extends Person {                        24. System.out.println(e.empID);

17. String emplD = “0000”;                                        25. }

18. public Employee(String id) { empID = id; }                26. }

What is the result?

A. 4321                                                                B. 0000

C. An exception is thrown at runtime.                        D. Compilation fails because of an error in line 18.

Question 17

11. public class Test {                                                        17. System.out.print(”collie “);

12. public enum Dogs {collie, harrier, shepherd};                18. case default:

13. public static void main(String [] args) {                                19. System.out.print(”retriever “);

14. Dogs myDog = Dogs.shepherd;                                        20. case harrier:

15. switch (myDog) {                                                                21. System.out.print(”harrier “);

16. case collie:                                                                        22. }}}

What is the result?

A. harrier                        B. shepherd                C. retriever       

D. Compilation fails.                        E. retriever harrier                F. An exception is thrown at runtime.

Question 18

11. public static void main(String[] args) {                        14. case 3: System.out.println(”three”); break;

12. Integer i = new Integer(1) + new Integer(2);                15. default: System.out.println(”other”); break;

13. switch(i) {                                                                16. }}

What is the result?

A. three                B. other                C. An exception is thrown at runtime.

D. Compilation fails because of an error on line 12.

E. Compilation fails because of an error on line 13.

F. Compilation fails because of an error on line 15.

Question 19

11. public static void main(String[] args) {                        16. System.out.println(”zero”);

12. String str = “null’;                                                        17. } else {

13. if (str == null) {                                                        18. System.out.println(”some”);

14. System.out.println(”null”);                                        19. }

15. } else (str.length() == 0) {                                        20. }

What is the result?

A. null        B. zero        C. some                D. Compilation fails.                E. An exception is thrown at runtime.

Question 20

11. public static Iterator reverse(List list) {                16. List list = new ArrayList();

12. Collections.reverse(list);                                17. list.add(” 1”); list.add(”2”); list.add(”3”);

13. return list.iterator();                                        18. for (Object obj: reverse(list))

14. }                                                                        19. System.out.print(obj + “,”);

15. public static void main(String[] args) {                20. }

 'What is the result?

A. 3,2, 1,                B. 1, 2, 3,                C. Compilation fails.

D. The code runs with no output.        E. An exception is thrown at runtime.

二、程序改错

请指出程序存在的问题并改正如果没有问题,请写正确

1.———————————————————————————————————

abstract class Name {

    private String name;

    public abstract boolean isStupidName(String name){}

}

2.———————————————————————————————————

public class Something {

    void doSomething() {

        private String s = "";

        int l = s.length();

    }

}

3.———————————————————————————————————

public class Something {

    public int addOne(final int x) {

        return ++x;

    }

}

4.———————————————————————————————————

public class Something {

    public static void main(String[] args) {

        Something s = new Something();

        System.out.println("s.doSomething() returns " + doSomething());

    }

    public String doSomething() {

        return "Do something ...";

    }

}

5.———————————————————————————————————

下程序实现一个简单的栈

public abstract class Stack {

    private Listelements;

    public Stack() {

        elements = new ArrayList();

    }

    public void push(Object e) {

        elements.add(e);

    }

    public Object pop() {

        if (elements.size() == 0)

            throw new EmptyStackException();

        return elements.remove(elements.size() - 1);

    }

    public void clear() {

        for (int i = 0; i < elements.size(); i++) {

            elements.remove(i);

        }

    }

}

三、写出程序运行结果

1.———————————————————————————————————

public class Example {

    public static void main(String args[]) {

        String s1 = "abc";

        String s2 = "de";

        s2.concat("f");

        String s3 = s1.concat(s2.toUpperCase());

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

    }

}

2.———————————————————————————————————

class TestA {

    public void start() { System.out.println("TestA"); }

}

public class TestB extends TestA {

    public void start() { System.out.println("TestB"); }

    public static void main(String[] args) {

        ((TestA) new TestB()).start();

    }

}

3.———————————————————————————————————

public final class PhoneNumber {

    private final short areaCode;

    private final short prefix;

    private final short lineNumber;

    public PhoneNumber(int areaCode, int prefix, int lineNumber) {

        this.areaCode = (short) areaCode;

        this.prefix = (short) prefix;

        this.lineNumber = (short) lineNumber;

    }

    public boolean equals(Object o) {

        if (o == this)

            return true;

        if (!(o instanceof PhoneNumber))

            return false;

        PhoneNumber pn = (PhoneNumber) o;

        return pn.lineNumber == lineNumber && pn.prefix == prefix

                && pn.areaCode == areaCode;

    }

    public static void main(String[] args) {

        Mapm = new HashMap();

        m.put(new PhoneNumber(707, 867, 5309), "Jenny");

        System.out.println(m.get(new PhoneNumber(707, 867, 5309)));

    }

}

4.———————————————————————————————————

class Super {

    public Super() {

        overrideMe();

    }

    public void overrideMe() {

    }

}

public final class Sub extends Super {

    private final Integer d;

    Sub() {

        d = new Integer(0);

    }

    public void overrideMe() {

        System.out.println(d);

    }

    public static void main(String[] args) {

        Sub sub = new Sub();

        sub.overrideMe();

    }

}

5.———————————————————————————————————

public class SetList {

    public static void main(String[] args) {

        Setset = new TreeSet();

        Listlist = new ArrayList();

        for (int i = -3; i < 3; i++) {

            set.add(i);

            list.add(i);

        }

        for (int i = 0; i < 3; i++) {

            set.remove(i);

            list.remove(i);

        }

        System.out.println(set + " " + list);

    }

}

四、编程

1、快速排序(Quicksort)算法过程

设要排序的数组是A[0]……A[N-1],首先任意选取一个数据(通常选用第一个数据)作为关键数据,然后将所有比它小的数都放到它前面,所有比它大的数都放到它后面,这个过程称为一趟快速排序。一趟快速排序的算法是:

1)设置两个变量I、J,排序开始的时候:I=1,J=N;

2)以第一个数组元素作为关键数据,赋值给X,即 X=A[1];

3)从J开始向前搜索,即由后开始向前搜索(J=J-1),找到第一个小于X的值,让该值与X交换;

4)从I开始向后搜索,即由前开始向后搜索(I=I+1),找到第一个大于X的值,让该值与X交换;

5)重复第3、4步,直到 I=J;

以下是快速排序的java实现,请填写空白处代码

public class QuickSort {

    public static int[] QuickSort0(int[] pData, int left, int right) {

        int i = left, j = right;

        int middle, strTemp;

        middle = pData[(left + right) / 2];

        do {

            while (          )

                i++;

            while ((pData[j] > middle) && (j > left))

                          ;

            if (          ) {

                strTemp = pData[i];

                pData[i] = pData[j];

                pData[j] = strTemp;

                i++;

                j--;

            }

        } while (i <= j);

        if (          ) {

            QuickSort0(pData, left, j);

        }

        if (          )

            QuickSort0(pData, i, right);

        return pData;

    }

    public static void main(String[] argv) {

        int[] pData = { 1, 84, 85, 67, 600, 88, 999 };

        QuickSort0(pData, 0, pData.length - 1);

        System.out.println(Arrays.toString(pData));

    }

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
java学习代码,分享史上java最牛逼,最简短的代码
位运算符
Java第一次作业
java第一次作业
最全的Java笔试题库之选择题篇-总共234道【1~60】
《Java 程序设计》模拟试题
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服