题目内容

下面题目的运行结果是class Super { int i=0; public Super(String a) { System.out.println("A"); i=1; } public Super() { System.out.println("B"); i+=2; }}class Demo extends Super { public Demo(String a) { System.out.println("C"); i=5; } public static void main(String[] args) { int i=4; Super d = new Demo("A"); System.out.println(d.i); }}

A. C5
B. C7
C. BC5
D. BC4

查看答案
更多问题

写出下面题目的运行结果:class Fu { boolean show(char a){ System.out.println(a); return true; }}class Demo extends Fu { public static void main(String[] args) { int i=0; Fu f=new Demo(); Demo d=new Demo(); for(f.show('A'); f.show('B')&&(i<2);f.show('C')) { i++; d.show('D'); } } boolean show(char a) { System.out.println(a); return false; }}

A
B
C. BA
D. AB

下列选项中关于java中this关键字的说法错误的是( )

A. this关键字是在对象内部指代对象自身的引用
B. this关键字可以在类中的任何位置使用
C. this只和特定的对象关联,而不是和类关联
D. 同一个类的不同对象有不同的this

编译运行如下java代码,输出结果是( )//父类引用不能访问子类特有的属性 class Base{ public void method(){ System.out.print("Base method"); } } class Child extends Base{ public void methodB(){ System.out.print("Child methodB"); } } class Sample{ public static void main(String[] args){ Base base = new Child(); base.methodB(); } }

A. Base method
B. Child methodB
C. Base method Child methodB
D. 编译错误

编译运行如下java代码,输出结果是( ) class Person{ String name = "person"; public void shout(){ System.out.print(name); } } class Student extends Person{ String name = "student"; String school = "school"; } public class Test{ public static void main(String[] args){ Person p = new Student(); p.shout(); } }

A. person
B. student
C. person student
D. 编译错误

答案查题题库