举一反三
- 以下代码调试结果 class Base {} class Sub extends Base {} public class CEx{ public static void main(String argv[]){ Base b = new Base(); Sub s = (Sub) b; } }
- 当你编译运行下列程序代码,会得到什么结果? 。 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); } }
- 选择下面程序运行的结果,并说明原因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();}}
- 对于一下程序,其运行结果为 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(); } }
- 以下程序的编译和运行结果为? 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(); } }
内容
- 0
如何能使程序调用Base类的构造方法输出"base constructor";...ived() {//Three}}
- 1
(6-2)以下代码会出现编译错误。 class Base{ public Base () { System.out.println("1"); } public void Base () { System.out.println("2"); } }
- 2
有以下程序: #include <iostream> using namespace std; class Base{ public: Base(int x=0) {cout<<x;} }; class Derived : public Base{ public: Derived(int x=0) {cout<<x;} private: Base val; }; int main(){ Derived d(1); return 0; } 程序的输出结果是
- 3
给出以下代码,请问插入以下哪些语句可以使程序编译通过?( )class Base{public Base(int i){}}public class Example extend Base{public static void main (String arg[]){Example e = new Example(10);}Example(int i){Super(i);}Exanple(String s, int i){this(i);//插入代码处}}请选择一个正确答案: A: Example d = new Example(); B: Super(); C: This(“Hello”,10); D: Base b = ne Base(10);
- 4
定义如下类Base,是setNum()方法的重载方法。 class Base{ public void setNum (int a,int b,float c){ } }