第三章单元测试
  1. 根据语句Person p=new Student();可以判断出( )。

    public class Test{

    public static void main(String[] args){

    Point p1 = new Point(10, 20);

    Point p2 = p1.move(-5, 3);

    System.out.println(p1.getInfo());

    System.out.println(p2.getInfo());

    }

    }



  2. A:Person类的父类是Object类
    B:Student类的父类是Object类
    C:Student类是Person类的直接子类或者间接子类
    D:都正确

    答案:Student类是Person类的直接子类或者间接子类

  3. 根据申明public abstract class Document{......}下面说法中错误的是( )。

  4. A:Document类一定有抽象方法
    B:Document类一定有toString方法
    C:语句Document doc = null;在语法上一定是正确的
    D:Document类可以作为方法的返回类型

    答案:Document类一定有抽象方法

  5. 根据语句String name=((NamedBean)bean).name;可以断定NamedBean类中一定申明了name属性。( )

  6. A:对 B:错
    答案:错
  7. 能够改正下面程序中语法错误的选项是( )。

    public class Test{

    String hello = “Hello, ”;

    public static void main(String[] args){

    String john = “John”;

             String info = hello + john;

             System.out.println(info);

    }

    }



  8. A:修改String info = hello + john;为:
    String info = john;
    B:修改String hello = “Hello, ”;为:
    static String hello = “Hello”;
    C:修改public static void main为:
    public void main
    D:修改String info = hello + john;为:
    String info = new Test().hello + john;

    答案:修改String info = hello + john;为:
    String info = john;
    ###修改String hello = “Hello, ”;为:
    static String hello = “Hello”;
    ###修改public static void main为:
    public void main
    ###修改String info = hello + john;为:
    String info = new Test().hello + john;

  9. 根据以下程序选择正确的说法( )。

    abstract class Animal{

    public String sound();

    }

    class Dog extends Animal{

    public String sound(){return “汪汪”;}

    }

    class Cat extends Animal{

    public String sound(){return “喵喵”;}

    }

    public class Test{

    public static void main(String[] args){

    Animal[] zoo = {new Dog(), new Dog(), new Cat()};

    for(int i=0; i<zoo.length; i++) System.out.println(zoo[i].sound());

    }

    }



  10. A:语法上Cat c = (Cat)new Dog();是一条正确的语句
    B:程序运行输出如下结果:
    汪汪
    汪汪
    喵喵
    C:语法上Cat c = (Cat)new Animal();是一条正确的语句
    D:语法上Cat c = (Cat)zoo[0];是一条正确的语句

    答案:程序运行输出如下结果:
    汪汪
    汪汪
    喵喵
    ###语法上Cat c = (Cat)zoo[0];是一条正确的语句

点赞(4) dxwkbang
返回
顶部