更多"现有:      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)}} 执行下列代码的结果是哪项?() Pencil pen=new Pencil(); (( RubberPencil) pen).write( "Hello");
A. Write Hello
B. Rubber Write Hello
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) {
[单项选择] 现有: interface I { void go(); } abstract class A implements I { } class C extends A { void go(){ } } 结果是什么?()
A. 代码通过编译
B. 由于第1行的错误导致编译失败
C. 由于笫3行的错误导致编译失败
D. 由于第6行的错误导致编译失败
[单项选择] 现有: 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. 运行时抛出异常
[单项选择] 现有: 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
[单项选择] 现有两个文件: 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
[多项选择] 现有2个文件: package x; public class X{ public static void doX() {System.out.print("doX");} } 和: class Find{ public static void main(String [] args) { //insert code here } } 哪两行分别插入到类Find的第3行将编译并产生输出“doX”?()
A. doX();
B. X.doX();
C. x.X.doX();
D. x.X myX=new x.X();myX.doX();
[单项选择] 现有: 1. interface Animal f 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat implements Feline { 8. public void eat() { } 9. } 和以下三个接口声明: interface Feline extends Animal ( ) interface Feline extends Animal {void eat(); } interface Feline extends Animal {void eat() { } } 分别插入到第5行,有多少行可以编译?
A. 0
B. 1
C. 2
D. 3
[单项选择] 现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat implements Feline { 8. public void eat() { } 9. } 和以下三个接口声明: interface Feline extends Animal { } interface Feline extends Animal { void eat(); } interface Feline extends Animal { void eat() { } } 分别插入到第 5 行,有多少行可以编译?()
A. 0
B. 1
C. 2
D. 3