一个抽象类中的所有方法都必须是抽象的。 我的答案:×
接口练习已完成
1
关于接口下面不正确的说法是:
? ? ? ?
A、接口不支持多重继承 B、接口所有方法是抽象的
C、接口里的方法访问属性均为public D、定义接口的关键字是implements 我的答案:A 错误
2
Interface可以被以下哪个修饰符修饰
? ? ? ?
A、private B、class C、public D、static
我的答案:C
3
关于接口的定义和实现,以下描述正确的是:
? ? ? ?
A、接口定义的方法只有声明没有实现 B、接口定义中的变量都必须写明final和static
C、如果一个接口由多个类来实现,则这些类在实现该接口中的方法时采用统一的代码 D、如果一个类实现了接口,则必须实现该接口中的所有方法,但方法可不为为public 我的答案:A 错误
4
有如下的接口定义: public interface MyInterface
{
float k = 10; }
下列选项哪一项指令不能替代上列指令: float k=10;?
? ? ? ?
A、final float k = 10; B、private float k = 10; C、static float k = 10; D、public float k; 我的答案:D
5
一个类只能继承单个父类,一个类只能履行一个接口。 我的答案:×
6
接口不能声明构造函数。 我的答案:√
接口回调练习已完成
1
给出如下程序: interface InterfaceA{ }
abstract class ClassA{ }
class ClassB extends ClassA implements InterfaceA{
void g(){ abstract void g(); String s=\void f();
System.out.print(s);
}
public void f(){
System.out.print(\} }
public class E { }
其运行结果是?
? ? ? ?
public static void main(String[] args) { }
ClassA a=new ClassB(); InterfaceA b=new ClassB(); a.g(); b.f();
A、编译正确,但无运行结果
B、编译错误:InterfaceA b=new ClassB(); C、good good D、以上都不对 我的答案:C
2
给定以下程序片段,结果为? interface InterfaceA{ }
class ClassA implements InterfaceA{
public void f(){ String s=\void f();
System.out.print(s); } }
class ClassB{
void g(InterfaceA a){
a.f(); } }
public class E { }
? ? ? ?
public static void main(String[] args) { }
ClassB b=new ClassB(); b.g(new ClassA());
A、Hello
B、编译正确,但无运行结果 C、编译错误:b.g(new ClassA()) D、以上都不对 我的答案:A
3
给定如下程序,运行结果为:
interface B{ }
class A implements B{ }
public void f(){ }
public static void main(String[] args) { }
B b=new A(); b.f();
System.out.println(\!\
void f();
? ? ? ?
A、执行错误 B、I love java! C、编译错误 D、以上都不对 我的答案:B
1
下面哪个是对字符串String的正确定义
? ? ? ?
A、String s1=null; B、String s2='null'; C、String s3=(String)'abc'; D、String s4=(String)'\?'; 我的答案:A得分: 20.0分
2
字符串s=”Java”,找出字母v在字符串s中的位置,以下哪个选项是正确的
? ? ? ?
A、mid(2,s); B、charAt(2); C、indexOf(s);
D、s.indexOf('v');
我的答案:D得分: 20.0分
3
编译及运行以下代码,下列选项哪个是正确的 String s=new String(\ int iBegin=1; char iEnd=3;
System.out.println(s.substring(iBegin,iEnd));
? ? ? ?
A、输出Bic B、输出ic C、输出icy
D、编译错误
我的答案:B得分: 20.0分