2023年11月15号期中测验选择题(Java)
最佳答案 问答题库818位专家为你答疑解惑
本篇续接《2023年11月15号期中测验判断题(Java)》->传送门
2-1
以下程序运行结果是
public class Test extends Father{private String name="test";public static void main(String[] args){Test test = new Test();System.out.println(test.getName());}
}
class Father{private String name="father";public String getName() {return name;}
}
A. father
B. 编译出错
C. test
D. 运行出错,无输出
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
2-3
如下代码的输出是( )。
public class Test {public static void main(String[] args) {new Person().printPerson();new Student().printPerson();}
}class Student extends Person {private String getInfo() {return "Student";}
}class Person {private String getInfo() {return "Person";}public void printPerson() {System.out.println(getInfo());}
}
A.
Person Person
B.
Person Student
C.
Stduent Student
D.
Student Person
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( );
2-5
如下在一个Java抽象类中对抽象方法的声明哪个是正确的?
A.
public abstract method();
B.
public abstract void method();
C.
public void abstract method();
D.
public abstract void method() {}
2-6
有如下程序代码,程序执行的结果是:( )。
class Base {static void test() {System.out.println("Base.test()");}
}class Child extends Base {static void test() {System.out.println("Child.test()");Base.test(); // Call the parent method}
}public class Main {public static void main(String[] a) {Child.test();}
}
A.
Child.test()
Base.test()
B.
Base.test()
Base.test()
C.
Base.test()
Child.test()
D.
Runtime error. Cannot override a static method by an instance method
2-7
有如下程序代码,执行的结果是( )。
class Father {int a = 100;int b = 200;public void print() {System.out.println(a + " " + b);}
}class Child extends Father {int b = 300;int c = 400;public void print() {System.out.println(a + " " + b + " " + c);}public void printExtend() {System.out.println(c);}}public class Main {public static void main(String[] a) {Father obj=new Child();System.out.println(obj.a+" "+obj.b); obj.print(); }
}
A.
100 200
100 200 400
B.
100 300
100 300 400
C.
100 300
100 200 400
D.
100 200
100 300 400
2-8
有如下代码,程序执行结果是:( )。
abstract class Person {public abstract void eat();
}
public class Main {public static void main(String[] a) {Person p = new Person() {public void eat() {System.out.println("eat something");}};p.eat();}
}
A.
空字符串
B.
编译错误
C.
eat something
D.
运行错误
2-9
父类的引用指向自己子类的对象是()的一种体现形式。
A.
封装
B.
继承
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; }
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
2-12
可以用于在子类中调用被重写父类方法的关键字是()
A.
this
B.
implements
C.
extends
D.
super
2-13
Java中( ) 。
A.
一个子类可以有多个父类,一个父类也可以有多个子类
B.
一个子类可以有多个父类,但一个父类只可以有一个子类
C.
一个子类可以有一个父类,但一个父类可以有多个子类
D.
上述说法都不对
2-14
将以下哪种方法插入行3是不合法的。
public class Test1{public float aMethod(float a,float b){ }
}
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){ }
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();}
2-16
以下关于继承的叙述正确的是( )。
A.
在Java中类只允许单一继承
B.
在Java中一个类只能实现一个接口
C.
在Java中一个类不能同时继承一个类和实现一个接口
D.
在Java中接口只允许单一继承
2-17
下面说法不正确的是( )
A.
一个子类的对象可以接收父类对象能接收的消息;
B.
当子类对象和父类对象能接收同样的消息时,它们针对消息产生的行为可能不同;
C.
父类比它的子类的方法更多;
D.
子类在构造函数中可以使用super( )来调用父类的构造函数;
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
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 {}
2-20
在Java中,能实现多重继承效果的方式是( )。
A.
接口
B.
继承
C.
内部类
D.
适配器
2-21
下列选项中,用于定义接口的关键字是( )。
A.
interface
B.
implements
C.
abstract
D.
class
2-22
对于下列代码:
class Parent {public int addValue( int a, int b) {int s;s = a+b;return s;}
}
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...}
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"2023年11月15号期中测验选择题(Java)":http://eshow365.cn/6-39497-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!