更多"现有:      c"的相关试题:
[单项选择] 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?()
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
[单项选择] 1. interface TestA { String toString(); } 2. public class Test { 3. public static void main(String[] args) { 4. System.out.println(new TestA() { 5. public String toString() { return “test”; } 6. } 7. } 8. } What is the result?()
A. test
B. null
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 1.
E. Compilation fails because of an error in line 4.
F. Compilation fails because of an error in line 5.
[单项选择] 现有: 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(); ) } 运行结果是哪项?()
A. TeStA
B. TeStB
C. 编译失败
D. 运行时抛出异常
[单项选择] public class TestA{ public void methodA() throws IOException{ //…… } } public class TestB extends TestA{ public void methodA() throws EOFException{ //…… } } public class TestC extends TestA{ public void methodA() throws Exception{ //…… } } 当编译类TestC的时候,结果是哪项?()
A. 正常
B. 编译错误
C. 运行错误
D. 以上都不对
[单项选择] public class TestA{ public void methodA() throws IOException{ //…… } } public class TestB extends TestA{ public void methodA() throws EOFException{ //…… } } public class TestC extends TestA{ public void methodA() throws Exception{ //…… } } 当编译类TestC的时候,结果是哪项?()
A. 正常
B. 编译错误
C. 运行错误
D. 以上都不对
[单项选择] 现有 public class Parentt public void change (int x){) ) public class Child extends Parent{ //覆盖父类change方法 } 下列哪个声明是正确的覆盖了父类的change方法?()
A. protected void change (int x){}
B. public void change(int x, int y){}
C. public void change (int x){}
D. public void change (String s){}
[单项选择] 现有: 1 Interface F{} 2 class A implements F{} 3 class B extends A{} 4 class C extends B{ 5 public static void main(String[] args){ 6 B b=new B(); 7 //inSert C0de here 8 } 9 } 下列哪行代码插入到第7行,将抛出java.lang.ClassCaseException异常()
A. A a=b;
B. F f= (C)b;
C. F f= (A)b;
D. B bb= (B)(A)b;
[单项选择] 现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void erase (String content){ System.out.println ("Erase"+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write ("Hello"); pen.erase ("Hello");
A. Write Hello Erase Hello
B. Erase Hello Write Hello
C. 编译错误
D. 运行时抛出异常
[多项选择] 现有 1. class Calc { 2. public static void main(String [] args) { 3. try { 4. int x = Integer.parselnt ("42a") ; 5. //insert code here 6. System.out.print ("oops"); 7. } 8. } 9. } 下面哪两行分别插入到第五行,会导致输 "oops" ? ()
A. } catch (IllegalArgumentException e) {
B. } catch (IllegalStateException c) {
C. } catch (NumbelFormatException n) {
D. } catch (ClassCastException c) {
[单项选择] 现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void write (String content){ System.out.println ("Rubber Write"+content); } public void erase (String content){ System.out.println ("Erase "+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write("Hello");
A. Write Hello
B. Rubber Write Hello
C. 编译错误
D. 运行时抛出异常
[单项选择] 现有: class Ifs { public static void main (String [] args) { boolean state=false; int i=2; if( (++i>2) && (state=true)) i++; if( (++i>4) l l (state=false)) i++; System.out .println (i); } } 结果为:()
A. 6
B. 5
C. 4
D. 编译失败
[单项选择] 现有: class Test4 { public static void main (String [] args) { boolean X=true; boolean y=false; short Z=42; if((z++==42) && (y=true))z++; if((x=false) || (++z==45)) z++; System. out.println(¨z=”+z); } } 结果为:()
A. Z=42
B. z=44
C. Z= 45
D. z= 46
[单项选择] 现有: class Test2 f public static void main (String [] args) { short a,b,C; a=l; b=2; C=a+b; a+=2: } 以上代码中,哪一句是错误的?()
A. a=1:
B. C=a+b;
C. a+=2;
D. short a,b,C;
[多项选择] 现有: class HorseRadish { //insert code here protected HorseRadish (int x) { System.out.println ("bok choy"); } } class Wasabi extends HorseRadish { public static void main (String [] args){ Wasabi w- new Wasabi(); } } 分别插入到第2行,哪两项允许代码编译并产生”bok choy”输出结果()
A. protected HorseRadish() {this (42);}
B. protected HorseRadish() {}
C. //just a comment
D. protected HorseRadish() { new HorseRadish (42);}
[单项选择] 现有代码片段: String s="123"; String sl=S+456; 请问sl的结果是哪项?()
A. 123456
B. 579
C. 编译错误
D. 运行时抛出异常
[单项选择] 现有: class Top { static int X=l; public Top() { x*=3; } } class Middle extends Top { public Middle() {x+=l; } public static void main(String [] args) { Middle m=new Middle(); System.out.println (x); } } 结果是什么?()
A. 2
B. 3
C. 4
D. 编译失败
[单项选择] 现有: class Cat { Cat (int c) {System.out.print {"cat"+c+" "); } } class SubCat extends Cat { SubCat (int c){super (5); System.out.print ("cable");} SubCat() { this (4); } public static void main (String [] args) { SubCat s= new SubCat(); } } 结果为:()
A. cat5
B. cable
C. cat5 cable
D. cable cat5
[单项选择] 现有: class Guy { String greet() { return "hi"; } } class Cowboy extends Guy { String greet() { return. "howdy";}} class Wrangler extends Cowboy { String greet() { return "orch!"; } } class Greetings2 { public static void main (String [] args) { Guy g=new Wrangler(); Guy g2=new Cowboy(); Wrangler w2=new Wrangler(); System. out .print (g.greet()+g2.greet()+w2 .greet()); } } 结果是什么?()
A. hi hi ouch!
B. ouch! howdy ouch!
C. hi howdy ouch!
D. 编译失败
E. 运行的咐候有异常抛出
[单项选择] 现有两个文件: package X; public class X { public static void doX() {System.out.print ("doX"); } } 和: import x.X; class Find { publiC static void main (String [] args) { X myX=new X(); myX.doX(); X.doX(); x.X.aoX(): x.X myX2=new x.X(); myx2 .doX(); } } 结果为:()
A. Find类中第4行出现一个错误,编译失败。
B. Find类第5行出现一个错误,编译失败。
C. Find类第6行出现一个错误,编译失败。
D. doX doX doX doX