Base
BaseBase
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第1题:
写出程序运行的结果
Public class Base
Public virtual string Hello() {return “Base”;}
Public class Sub:Base
Public override string Hello() {return “Sub”;}
1. Base b = new Base(); b.Hello;
2. Sub s = new Sub(); s.Hello;
3. Base b = new Sub (); b.Hello;
4. Sub s = new Base(); s.Hello;
第2题:
以下程序的编译和运行结果为?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
A.amethod();
}
public void myfunc(){
System.out.println("My Func");
}
public void amethod(){
myfunc();
}
}
A.输出结果为 My Func
B.编译指示 Base 类中无抽象方法
C.编译通过,但运行时指示Base 类中无抽象方法
D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。
第3题:
A.编译指示带有final 方法的类自己必须定义为final
B.编译指示不能继承含有final 方法的类
C.运行错误,原因是Base类没有定义为final类
D.运行输出 amethod
第4题:
设有如下代码:
class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;
public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
则在 //Here处插入哪个代码将不出现编译和运行错误。
A.b=m;
B.m=b;
C.d =i;
D.b1 =i;
第5题:
public class Alpha{ private static Character() ids; public static void main( String[] args){ ids = new Character[args.length]; for (int i=0; i
第6题:
public class Alpha{ public static void main( string[] args ){ if ( args.length == 2 ) { if ( args.[0].equalsIgnoreCase(“-b”) ) System.out.println( new Boolean( args[1] )); } } } And the code is invoked by using the command: java Alpha –b TRUE What is the result?()
第7题:
What will be written to the standard output when the following program is run?() class Base { int i; Base() { add(1); } void add(int v) { i += v; } void print() { System.out.println(i); } } class Extension extends Base { Extension() { add(2); } void add(int v) { i += v*2; } } public class Qd073 { public static void main(String args[]) { bogo(new Extension()); } static void bogo(Base b) { b.add(8); b.print(); } }
第8题:
interface Beta {} class Alpha implements Beta { String testIt() { return “Tested”; } } public class Main1 { static Beta getIt() { return new Alpha(); } public static void main( String[] args ) { Beta b = getIt(); System.out.println( b.testIt() ); } } What is the result?()
第9题:
AAA
BBB
Compilation fails.
The code runs with no output.
第10题:
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
The code runs, outputing a concatenated list of the arguments passed to the program.
第11题:
TestA
TestB
Compilation fails.
An exception is thrown at runtime.
第12题:
9
18
20
21
22
第13题:
设有类定义如下:
class Base{
public Base(int i){}
}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m = new MyOver(10);
}
MyOver(int i){
super(i);
}
MyOver(String s, int i){
this(i);
//Here
}
}
以下哪条语句可以安排在//Here处 ?
A.MyOver m = new MyOver();
B.super();
C.this("Hello",10);
D.Base b = new Base(10);
第14题:
A.编译错误
B.200
C.100200
D.100
第15题:
设有如下代码:
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef bj = new ObRef();
Base b = new Base();
Object obj1 = new Object();
IFace obj2 = new CFace();
//Here
}
}
则在 //Here处插入哪个代码将不出现编译和运行错误。
A.obj1=obj2;
B.b=obj;
C.obj=b;
D.obj1=b;
第16题:
class MyThread extends Thread { public void run() { System.out.println(“AAA”); } public void run(Runnable r) { System.out.println(“BBB”); } public static void main(String[] args) { new Thread(new MyThread()).start(); } } What is the result?()
第17题:
public class Base { public static final String FOO = “foo”; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base)s).FOO); } } class Sub extends Base {public static final String FOO=bar;} What is the result?()
第18题:
class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?()
第19题:
Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object. class Base { public void print( ) { System.out.println("base"); } } class Extention extends Base { public void print( ) { System.out.println("extension"); // insert line of implementation here } } public class Q294d { public static void main(String args[]) { Extention ext = new Extention( ); ext.print( ); } } Fill in a single line of implementation.()
第20题:
class Base { Base() { System.out.print(“Base”); } } public class Alpha extends Base { public static void main( String[] args ) { new Alpha(); new Base(); } } What is the result?()
第21题:
Tested
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第22题:
Base
BaseBase
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第23题:
true
null
false
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第24题:
foofoofoofoofoo
foobarfoobarbar
foobarfoofoofoo
foobarfoobarfoo
barbarbarbarbar
foofoofoobarbar
foofoofoobarfoo