A: BaseClass.MethodA
B: Class2.MethodA
C: Class1.MethodA
D: 都不是
举一反三
- 以下程序的运行结果是______ abstract class class1{abstract void method1();}class class2 extends class1{public void method1(){ System.out.println("子类");}}public class MainClass{public static void main(String args[]){class1 ac=new class2();ac.method1();}}
- class A{ public void method(){} public void methodA(){}} class B extends A{ public void method(){} public void methodB(){} }<br/>则若有 A a = new B();a.methodB();下列说法正确的是() A: 执行类A的方法method B: 执行类B的方法methodB C: 编译通过,无法执行 D: 编译出错
- 请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args[]){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}
- 以下语句能顺利通过编译: abstract class class1 { } public class mainClass { public static void main(String args[]) { class1 cs1=new class1(); } } 。()
- 给出下列程序的输出结果。import java.io.IOException;public class E {public static void main(String args[]){int m =10;try {methodA();m = 100;}catch(IOException e){m = 1000;}System.out.println(m);}public static void methodA() throws IOException{throw new IOException();}}
内容
- 0
智慧职教: public class Something { public static void main(String[] args) { Other o = new Other(); new Something().addOne(o); } public void addOne(final Other o) { o.i ; } } class Other { public int i; }
- 1
public class Example { public static void main(String[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); } } class Father { public void show() { System.out.println("hellofather"); } }
- 2
从下面四段代码中选择出正确的代码段() A: public class Something {public static void main(String[] args) {Other o = new Other();new Something().addOne(o);}public void addOne(final Other o) {o.i++;}}class Other {public int i;} B: public class Something {void doSomething () {private String s = ̶”;int l = s.length();}} C: abstract class Name {private String name;public abstract boolean isStupidName(String name) {}} D: public class Something {public int addOne(final int x) {return ++x; }}
- 3
Which two allow the class Thing to be instantiated using new Thing()? A: public class Thing { } B: public class Thing { public Thing() {} } C: public class Thing { public Thing(void) {} } D: public class Thing { public Thing(String s) {} } E: public class Thing { public void Thing() {} public Thing(String s) {} }
- 4
import java.io.IOException; public class ExceptionTest( public static void main (String[]args) try ( methodA(); ) catch (IOException e) ( system.out.printIn(“Caught IOException”); ) catch (Exception e) ( system.out.printIn(“Caught Exception”); ) ) public void methodA () { throw new IOException (); } What is the result?() A: The code will not compile. B: The output is caught exception. C: The output is caught IOException. D: The program executes normally without printing a message.