• 2023年11月15号期中测验选择题(Java)


    本篇续接《2023年11月15号期中测验判断题(Java)》->传送门

    单选题->  A        B        C        D 


     2-1

    以下程序运行结果是

    1. public class Test extends Father{
    2. private String name="test";
    3. public static void main(String[] args){
    4. Test test = new Test();
    5. System.out.println(test.getName());
    6. }
    7. }
    8. class Father{
    9. private String name="father";
    10. public String getName() {
    11. return name;
    12. }
    13. }

    A.        father

    B.        编译出错

    C.        test

    D.        运行出错,无输出

    正确答案:A

    解释:

    本题主要考查继承的重写(override)知识点,详见此篇标题五->传送门

    其中,Father是父类,Test继承Father,也就继承了其中的getName方法,但是继承后并未重写该方法,因此用Test类示例化的对象调用getName方法时本质上调用的是未重写的Father类中的方法,也就获取到Father类中的name变量的值,即"father"。


     2-2

    If a method defined in a derived class has the same name, return type and parameters with the base one, we call this situation as: (____)

    A.        overload

    B.        override

    C.        inheritance

    D.        construction

     

    正确答案:B

    解释:


    2-3

    如下代码的输出是( )。

    1. public class Test {
    2. public static void main(String[] args) {
    3. new Person().printPerson();
    4. new Student().printPerson();
    5. }
    6. }
    7. class Student extends Person {
    8. private String getInfo() {
    9. return "Student";
    10. }
    11. }
    12. class Person {
    13. private String getInfo() {
    14. return "Person";
    15. }
    16. public void printPerson() {
    17. System.out.println(getInfo());
    18. }
    19. }

    A.        Person Person

    B.        Person Student

    C.        Stduent Student

    D.        Student Person

    正确答案:A

    解释:


    2-4

    设类B是类C的父类,下列声明对象x1的语句中不正确的是?

    A.        B x1 = new B( );

    B.        B x1=new C( );

    C.        C x1 = new C( );

    D.        C x1=new B( );

    正确答案:D

    解释:


    2-5

    如下在一个Java抽象类中对抽象方法的声明哪个是正确的?

    A.        public abstract method();

    B.        public abstract void method();

    C.        public void abstract method();

    D.        public abstract void method() {}

    正确答案:B

    解释:


    2-6

    有如下程序代码,程序执行的结果是:( )。

    1. class Base {
    2. static void test() {
    3. System.out.println("Base.test()");
    4. }
    5. }
    6. class Child extends Base {
    7. static void test() {
    8. System.out.println("Child.test()");
    9. Base.test(); // Call the parent method
    10. }
    11. }
    12. public class Main {
    13. public static void main(String[] a) {
    14. Child.test();
    15. }
    16. }

    A.

    1. Child.test()
    2. Base.test()

    B.

    1. Base.test()
    2. Base.test()

    C.

    1. Base.test()
    2. Child.test()

    D.

    Runtime error. Cannot override a static method by an instance method

    正确答案:A

    解释:


    2-7

    有如下程序代码,执行的结果是( )。

    1. class Father {
    2. int a = 100;
    3. int b = 200;
    4. public void print() {
    5. System.out.println(a + " " + b);
    6. }
    7. }
    8. class Child extends Father {
    9. int b = 300;
    10. int c = 400;
    11. public void print() {
    12. System.out.println(a + " " + b + " " + c);
    13. }
    14. public void printExtend() {
    15. System.out.println(c);
    16. }
    17. }
    18. public class Main {
    19. public static void main(String[] a) {
    20. Father obj=new Child();
    21. System.out.println(obj.a+" "+obj.b);
    22. obj.print();
    23. }
    24. }

    A.

    1. 100 200
    2. 100 200 400

    B.

    1. 100 300
    2. 100 300 400

    C.

    1. 100 300
    2. 100 200 400

    D.

    1. 100 200
    2. 100 300 400

     

    正确答案:D

    解释:


    2-8

    有如下代码,程序执行结果是:( )。

    1. abstract class Person {
    2. public abstract void eat();
    3. }
    4. public class Main {
    5. public static void main(String[] a) {
    6. Person p = new Person() {
    7. public void eat() {
    8. System.out.println("eat something");
    9. }
    10. };
    11. p.eat();
    12. }
    13. }

    A.        空字符串

    B.        编译错误

    C.        eat something

    D.        运行错误

    正确答案:C

    解释:


    2-9

    父类的引用指向自己子类的对象是()的一种体现形式。

    A.        封装

    B.        继承

    C.        多态

    正确答案:C

    解释:


    2-10

    请问以下哪个程序代码体现了对象之间的 IS-A关系?

    A.

    public interface Color { } pulic class Shape { private Color color; }

    B.

    interface Component { } public class Container implments Component { private Component[] children; }

    C.

    public class Species { } public class Animal { private Species species; }

    正确答案:B

    解释:


    2-11

    给出以下Java程序代码,请问运行结果是()?

     
    

    interface Base { int k = 0; } public class Test implements Base { public staic void main(Strin[] args){ int i; Test obj = new Test(); i = obj.k; i = Test.k; i = Base.k; System.out.println(i); } }

    A.        无内容输出。

    B.        代码编译失败。

    C.        代码输出0

    D.        代码输出1

    正确答案:C

    解释:


    2-12

    可以用于在子类中调用被重写父类方法的关键字是()

    A.        this

    B.        implements

    C.        extends

    D.        super

    正确答案:D

    解释:


    2-13

    Java中( ) 。

    A.        一个子类可以有多个父类,一个父类也可以有多个子类

    B.        一个子类可以有多个父类,但一个父类只可以有一个子类

    C.        一个子类可以有一个父类,但一个父类可以有多个子类

    D.        上述说法都不对

    正确答案:C

    解释:


    2-14

    将以下哪种方法插入行3是不合法的。

    1. public  class  Test1{
    2.          public  float  aMethod(float  a,float  b){   }
    3. }

    A.        public  float  aMethod(float  a, float  b,float  c){  }

    B.        public  float  aMethod(float  c,float d){  }

    C.        public  int  aMethod(int  a, int b){  }

    D.        private float aMethod(int a,int b,int c){  }

    正确答案:B

    解释:


    2-15

    若A1、A2为已定义的接口 ,以下接口定义中没有语法错误的是(        ) 。

    A.        interface  B {  void print()  {  } }

    B.        abstract  interface  B { void print() }

    C.        abstract  interface  B  extends  A1,A2  { abstract  void  print(){  };}

    D.        interface  B  {  void  print();} 

    正确答案:D

    解释:


    2-16

    以下关于继承的叙述正确的是(     )。

    A.        在Java中类只允许单一继承

    B.        在Java中一个类只能实现一个接口

    C.        在Java中一个类不能同时继承一个类和实现一个接口

    D.        在Java中接口只允许单一继承

    正确答案:A

    解释:


    2-17

    下面说法不正确的是(     )

    A.        一个子类的对象可以接收父类对象能接收的消息;

    B.        当子类对象和父类对象能接收同样的消息时,它们针对消息产生的行为可能不同;

    C.        父类比它的子类的方法更多;

    D.        子类在构造函数中可以使用super( )来调用父类的构造函数;

    正确答案:C

    解释:


    2-18

    下面是People和Child类的定义和构造方法,每个构造方法都输出编号。在执行new Child("mike")的时候都有哪些构造方法被顺序调用?请选择输出结果 (    )

    class People {
            String name;
            public People() {
                   System.out.print(1);
            }
            public People(String name) {
                   System.out.print(2);
                   this.name = name;
            }
    }
    class Child extends People {
           People father;
           public Child(String name) {
                  System.out.print(3);
                  this.name = name;
                  father = new People(name + ":F");
           }
           public Child(){
                 System.out.print(4);
           }
    }
    

    A.        312

    B.        32

    C.        432

    D.        132

    正确答案:D

    解释:


    2-19

    下面哪个对类的声明是错误的?

    A.        class MyClass extends MySuperClass1, MySupperClass2 {}

    B.        public class MyClass{}

    C.        abstract class MyClass implements YourInterface1, Youriterface2 {}

    D.        private class MyClass {}

    E.        class MyClass extends MySuperClass implements YourInterface {}

    正确答案:A

    解释:


    2-20

    在Java中,能实现多重继承效果的方式是( )。

    A.        接口

    B.        继承

    C.        内部类

    D.        适配器

    正确答案:A

    解释:


    2-21

    下列选项中,用于定义接口的关键字是( )。

    A.        interface

    B.        implements

    C.        abstract

    D.        class

    正确答案:A

    解释:


    2-22

    对于下列代码:

    1. class Parent {
    2. public int addValue( int a, int b) {
    3. int s;
    4. s = a+b;
    5. return s;
    6. }
    7. }
    8. class Child extends Parent {   }  

    下述哪个方法可以加入类Child?

    A.        int addValue( int a,int b ){// do something...}

    B.        public void addValue (int a,int b ){// do something...}

    C.        public int addValue( int a ){// do something...}

    D.        public int addValue( int a,int b )throws MyException {//do something...}

    正确答案:C

    解释:


    已经到底咯~ 

  • 相关阅读:
    局域网基本概念和体系结构
    笔记wife_assistant
    Java项目:SSH电影在线售票管理系统
    数据库可视化工具分享 (DBeaver)
    【C++基础入门】41.C++中父子间的冲突
    Session会话追踪的实现机制
    解析后人类时代类人机器人的优越性
    Redis参数规范详解
    机器学习之ROC与AUC
    学会用数据分析汇报工作,升职加薪指日可待
  • 原文地址:https://blog.csdn.net/liKeQing1027520/article/details/134492364