chirp chirp
hello hello
chirp hello
编译错误
第1题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第2题:
class BitStuff { BitStuff go() { System.out.print("bits "); return this; } } class MoreBits extends BitStuff { MoreBits go() { System.out.print("more "); return this; } public static void main(String [] args) { BitStuff [] bs = {new BitStuff(), new MoreBits()}; for( BitStuff b : bs) b.go(); } } 结果为:()
第3题:
classBird{staticvoidtalk(){System.out.print("chirp");}}classParrotextendsBird{staticvoidtalk(){System.out.print("hello");}publicstaticvoidmain(String[]args){Bird[]birds={newBird(),newParrot()};for(Birdb:birds)b.talk();}}结果为:()
A.chirpchirp
B.chirphello
C.hellohello
D.编译失败
第4题:
现有: 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(); } } 结果为:()
第5题:
现有: class Bird { void talk() { System.out.print("chirp "); } } class Parrot2 extends Bird { protected void talk() { System.out.print("hello "); public static void main(String [] args) { Bird [] birds = {new Bird(), new Parrot2 () }; for( Bird b : birds) b.talk () ; } } 结果是什么 ?()
第6题:
class One { public One() { System.out.print(1); } } class Two extends One { public Two() { System.out.print(2); } } class Three extends Two { public Three() { System.out.print(3); } } public class Numbers{ public static void main( String[] argv) { new Three(); } } What is the result when this code is executed?()
第7题:
public class Base { public static final String FOO = “foo”; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base)s).FOO); } } class Sub extends Base {public static final String FOO=bar;} What is the result?()
第8题:
现有:classBird{voidtalk(){System.out.print("chirp");}}classParrot2extendsBird{protectedvoidtalk(){System.out.print("hello");publicstaticvoidmain(String[]args){Bird[]birds={newBird(),newParrot2()};for(Birdb:birds)b.talk();}}结果是什么?()
A.chirpchirp
B.hellohello
C.chirphello
D.编译错误
第9题:
class Bird { static void talk() { System.out.print("chirp "); } } class Parrot extends Bird { static void talk() { System.out.print("hello "); } public static void main(String [] args) { Bird [] birds = {new Bird(), new Parrot()}; for( Bird b : birds) b.talk(); } } 结果为:()
第10题:
class Passer { static final int x = 5; public static void main(String [] args) { new Passer().go(x); System.out.print(x); } void go(int x) { System.out.print(++x); } } 结果是什么?()