A: Example d = new Example();
B: Super();
C: This(“Hello”,10);
D: Base b = ne Base(10);
举一反三
- 当你编译运行下列程序代码,会得到什么结果? 。 private class Base{ Base(){ int i = 100; System.out.println(i); } } public class Pri extends Base{ static int i = 200; public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } }
- 如何能使程序调用Base类的构造方法输出"base constructor"; class Base{ Base(int i){ System.out.println("base constructor"); } Base(){ } } public class Sup extends Base{ public static void main(String argv[]){ Sup s= new Sup(); //One } Sup() { //Two } public void derived() { //Three } }
- 以下代码调试结果 class Base {} class Sub extends Base {} public class CEx{ public static void main(String argv[]){ Base b = new Base(); Sub s = (Sub) b; } }
- 选择下面程序运行的结果,并说明原因class Base{Base(){System.out.println("Base");}}public class Checket extends Base{Checket(){System.out.println("Checket");super();}public static void main(String[] arg){Checket c = new Checket();}}
- 给出下面的代码段 public class Base{ int x, y; static int z; public Base(int a,int b)<br/>{ x=a; y=b; } } 以下代码错误的是?(). A: Base b=new Base(); <br/>b.z=10; B: Base b=new Base(1,2); <br/>b.z=10; C: Base.z=10; D: Base b=new Base(1,2);<br/>b.x=2;
内容
- 0
下面( )方法是public void example(){}的重载方法。 A: private String example(){} B: public int example(String str){} C: public void example2(){} D: public int example(int m,float f){}
- 1
对于一下程序,其运行结果为 class Base{ public Base(){ System.out.print("C"); } } class Base2 extends Base{ public Base2(){ System.out.print("B"); } } public class TestDemo extends Base2{ int m=1; public TestDemo(){ System.out.println("A"); } public static void main(String args[]){ TestDemo t = new TestDemo(); } }
- 2
以下程序编译和运行会发生什么public class Q8 {int i = 20;static { int i = 10; }public static void main(String[] args) {Q8 a = new Q8();System.out.println(a.i);}}
- 3
阅读下列程序public class Example public static void main(String[]
- 4
(8-2)有如下类定义,为类Base中的变量a增加修饰符是合法的。 public class Base{ int a=8; public Base( int i ) { a = i; } }