测试题

作者: 我是老薛 | 来源:发表于2018-12-02 11:06 被阅读0次

    一、选择题

    1.Which four options describe the correct default values for array elements of the types indicated?(多选)
    A. int -> 0
    B. String -> "null"
    C. Dog -> null
    D. char -> '\u0000'
    E. float -> 0.0f
    F. boolean -> true

    2.Which one of these lists contains only Java programming language keywords? (多选)
    A.class, if, void, long, Int, continue
    B.goto, instanceof, native, finally, default, throws
    C.try, virtual, throw, final, volatile, transient
    D.strictfp, constant, super, implements, do
    E.byte, break, assert, switch, include

    3、Which will legally declare, construct, and initialize an array?
    A. int [] myList = {"1", "2", "3"};
    B. int [] myList = (5, 8, 2);
    C. int myList [] [] = {4,9,7,0};
    D. int myList [] = {4, 3, 7};

    4.Which is a reserved word in the Java programming language?
    A. method
    B. native
    C. subclasses
    D. reference
    E. array

    5、Which three are legal array declarations?(多选)
    A.int [] myScores [];
    B.char [] myChars;
    C.int [6] myScores;
    D.Dog myDogs [];
    Dog myDogs [7];

    6、

    public interface Foo 
    { 
        int k = 4; /* Line 3 */
    }
    

    Which three piece of codes are equivalent to line 3?
    A. final int k = 4;
    B. public int k = 4;
    C. static int k = 4;
    D. abstract int k = 4;
    E. volatile int k = 4;
    F. protected int k = 4;

    7、Which is the valid declarations within an interface definition?
    A. public double methoda();
    B. public final double methoda();
    C. static void methoda(double d1);
    D. protected void methoda(double d1);

    8、Which one is a valid declaration of a boolean?
    A. boolean b1 = 0;
    B. boolean b2 = 'false';
    C. boolean b3 = false;
    D. boolean b4 = Boolean.false();
    E. boolean b5 = no;

    9、Which three are valid declarations of a float?(多选)
    A.float f1 = -343;
    B.float f2 = 3.14;
    C.float f3 = 0x12345;
    D.float f4 = 42e7;
    E.float f5 = 2001.0D;
    float f6 = 2.81F;

    10、You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
    A. public
    B. private
    C. protected
    D. transient

    11、

    interface Base 
    {
        boolean m1 ();
        byte m2(short s);
    }
    

    which two code fragments will compile? (多选)
    A. interface Base2 implements Base {}
    B. abstract class Class2 extends Base
    { public boolean m1(){ return true; }}
    C. abstract class Class2 implements Base {}
    D. abstract class Class2 implements Base
    { public boolean m1(){ return (7 > 4); }}
    E. abstract class Class2 implements Base
    { protected boolean m1(){ return (5 > 7) }}

    12、

    public class Test { }
    

    What is the prototype of the default constructor?
    A. Test( )
    B. Test(void)
    C. public Test( )
    D. public Test(void)

    13、What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
    A. public
    B. abstract
    C. protected
    D. synchronized
    E. default access

    14、Which of the following is/are legal method declarations?
    A.protected abstract void m1();
    B.static final void m1(){}
    C.synchronized public final void m1() {}
    D.private native void m1();

    15、Which cause a compiler error?
    A. int[ ] scores = {3, 5, 7};
    B. int [ ][ ] scores = {2,7,6}, {9,3,45};
    C. String cats[ ] = {"Fluffy", "Spot", "Zeus"};
    D. boolean results[ ] = new boolean [] {true, false, true};
    E. Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)};

    16、

    class A 
    {  
        protected int method1(int a, int b) 
        {
            return 0; 
        } 
    }
    

    Which is valid in a class that extends class A?
    A. public int method1(int a, int b) {return 0; }
    B. private int method1(int a, int b) { return 0; }
    C. public short method1(int a, int b) { return 0; }
    D. static protected int method1(int a, int b) { return 0; }

    17、Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?
    A. final
    B. static
    C. private
    D. protected
    E. volatile

    18、

    public class While /* Line 1 */
    {
        public void loop() 
        {
            int x= 0;
            while ( 1 ) /* Line 6 */
            {
                System.out.print("value is " + (x + 1)); /* Line 8 */
            }
        }
    }
    

    Which statement is true?
    A. There is a syntax error on line 1.
    B. There are syntax errors on lines 1 and 6.
    C. There are syntax errors on lines 1, 6, and 8.
    D. There is a syntax error on line 6.

    19、

    public class Myfile 
    { 
        public static void main (String[] args) 
        {
            String a = args[1]; 
            String b = args[2]; 
            String c = args[3]; 
            System.out.print(c);
        } 
    }
    

    Select how you would start the program to cause it to print:2
    A. java Myfile 222
    B. java Myfile 1 2 2 3 4
    C. java Myfile 1 3 2 2
    D. java Myfile 0 1 2 3

    20、
    What will be the output of the program?

    public class WrapTest 
    {
        public static void main(String [] args) 
        {
            int result = 0;
            short s = 42;
            Long x = new Long("42");
            Long y = new Long(42);
            Short z = new Short("42");
            Short x2 = new Short(s);
            Integer y2 = new Integer("42");
            Integer z2 = new Integer(42);
            if (x == y) /* Line 13 */
                result = 1;
            if (x.equals(y) ) /* Line 15 */
                result = result + 10;
            if (x.equals(z) ) /* Line 17 */
                result = result + 100;
            if (x.equals(x2) ) /* Line 19 */
                result = result + 1000;
            if (x.equals(z2) ) /* Line 21 */
                result = result + 10000;
            System.out.println("result = " + result);
        }
    }
    

    A. result = 1
    B. result = 10
    C. result = 11
    D. result = 11010

    21、What will be the output of the program?

    public class Test178 
    { 
        public static void main(String[] args) 
        {
            String s = "foo"; 
            Object o = (Object)s; 
            if (s.equals(o)) 
            { 
                System.out.print("AAA"); 
            } 
            else 
            {
                System.out.print("BBB"); 
            } 
            if (o.equals(s)) 
            {
                System.out.print("CCC"); 
            } 
            else 
            {
                System.out.print("DDD"); 
            } 
        } 
    }
    

    A. AAACCC
    B. AAADDD
    C. BBBCCC
    D. BBBDDD

    22、What will be the output of the program?

    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. It compiles and runs printing nothing
    B. Compiles but fails at runtime
    C. Compile Error
    D. Prints "complete"

    23、Jar文件Poker.jar中已正确定义了一个类games.cards.Poker。在linux系统中用户想用以下命令运行Poker中的main方法:
    java games.cards.Poker
    用户需要怎么做?

    A. 把 Poker.jar 放在目录 /stuff/java中,并且设置 CLASSPATH 包含/stuff/java
    B. 把 Poker.jar 放在目录 /stuff/java中,并且设置 CLASSPATH 包
    含/stuff/java/.jar
    C. 把 Poker.jar 放在目录 /stuff/java中,并且设置 CLASSPATH 包
    含/stuff/java/Poker.jar
    D. 把 Poker.jar 放在目录/stuff/java/games/cards中, 并且设置
    CLASSPATH 包含 /stuff/java
    E.把 Poker.jar 放在目录/stuff/java/games/cards中, 并且设置
    CLASSPATH 包含/stuff/java/
    .jar
    F. 把 Poker.jar 放在目录 /stuff/java/games/cards中, 并且设置
    CLASSPATH 包含/stuff/java/Poker.jar

    24、给定一个编译好的class,源代码如下:

     package com.sun.sjcp;
     public class Commander {
          public static void main(String[] args) {
              // more code here
          }
      }
    

    假设class文件在 /foo/com/sun/sjcp/, 当前目录是 /foo/, classpath中已经包含了 "." (当前目录). 以下哪个命令能够正确运行Commander?
    A. java Commander
    B. java com.sun.sjcp.Commander
    C. java com/sun/sjcp/Commander
    D. java -cp com.sun.sjcp Commander
    E. java -cp com/sun/sjcp Commander

    25、Java的字符类型采用的是Unicode编码方案,每个Unicode码占用( )个比特位。
    A、8
    B、16
    C、32
    D、64

    二、编程题
    1、编写一个程序,从命令行终端输入一系列整数,整数之间以空格分隔。获取输入的整数,放到List中。然后对这些输入的数值求和,并输出。

    2、编写一个函数,输入参数是一个字符串(是一个四则运算表达式,只有 + - 两种运算符,没有括号),输出是浮点数。函数实现的功能就是计算输入的四则运算表达式的值,并作为函数返回值返回。
    要求不能使用第三方库来实现,而是自己写代码解析字符串进行运算。
    举例:
    输入 3+5-2 返回值为 6
    输入 13-8-5+2 返回值为 2

    3、假设一个学生成绩管理系统中有如下实体:
    学生:包括但不限于 学号、姓名等信息
    课程信息:课程编号、课程名等信息

    有这样一个java接口

    interface Manager{
       void selCourse(Student student, Course course);
       void delCourse(Student student, Course course);
       void showCourse(Student student);
    }
    

    上面代码中的Student 为建模后的学生类,Course 为课程信息类。
    1)selCourse方法的功能是学生选课,如果输入的学生或课程不存在,则需要抛出一个自定义异常。
    2)delCourse方法的功能是删除所选课程,如果输入的学生或课程不存在,则需要抛出一个自定义异常。
    3)showCourse方法的功能是输出指定学生所选的课程,如果输入的学生不存在,则需要抛出一个自定义异常。

    要求:
    1、编写一个类(可以有额外的附加类),实现上面定义的Manager接口
    2、学生信息和课程信息,在代码中写死,存放到数组中
    3、学生的选课信息,存放到数组中

    相关文章

      网友评论

          本文标题:测试题

          本文链接:https://www.haomeiwen.com/subject/krcjcqtx.html