n = 100;
i.setX( 100 );
o.getY().setX( 100 );
i = new Inner(); i.setX( 100 );
o.setY( i ); i = new Inner(); i.setX( 100 );
i = new Inner(); i.setX( 100 ); o.setY( i );
第1题:
当你编译运行下列程序代码,会得到什么结果?
private class Base{ Base(){ int i = 100; System.out.println(i); } }
public class Pri extends Base{ staticint i = 200;
public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } }
A.这段代码不能通过编译
B.输出200
C.输出100和200
D.输出100
第2题:
A.编译错误
B.200
C.100200
D.100
第3题:
package foo; public class Outer { public static class Inner { } } Which statement is true?()
第4题:
下面哪一个是合法的数组声明和构造语句()
第5题:
class Foo { private int x; publicFoo(intx) {this.x=x; } public void setX( int x) { this.x = x; } public int getX() { return x; } } public class Gamma { static Foo fooBar( Foo foo) { foo = new Foo( 100); return foo; } public static void main( String[] args) { Foo foo = new Foo( 300); System.out.print( foo.getX() + “-“); Foo fooFoo = fooBar( foo); System.out.print( foo.getX() + “-“); System.out.print( fooFoo.getX() + “-“); foo = fooBar( fooFoo); System.out.print( foo.getX() + “-“); System.out.prmt( fooFoo.getX()); } } What is the output of this program?()
第6题:
10. class Inner { 11. private int x; 12. public void setX( int x) { this.x = x; } 13. public int getX() { return x; } 14. } 15. 16. class Outer { 17. private Inner y; 18. public void setY( Inner y) { this.y = y; } 19. public Inner getY() { return y; } 20. } 21. 22. public class Gamma { 23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner(); 26.int n=10; 27. i.setX(n); 28. o.setY(i); 29. // insert code here 30. System.out.println( o.getY().getX()); 31. } 32. } Which three code fragments, added individually at line 29, produce the output 100?()
第7题:
class Birds { public static void main(String [] args) { try { throw new Exception(); } catch (Exception e) { try { throw new Exception(); } catch (Exception e2) { System.out.print("inner "); } System.out.print("middle "); } System.out.print("outer "); } } 结果为:()
第8题:
new Inner(); // At line 3
new Inner(); // At line 8
new o.Inner(); // At line 8
new Outer.Inner(); // At line 8
第9题:
n = 100;
i.setX( 100);
o.getY().setX( 100);
i = new Inner(); i.setX( 100);
o.setY( i); i = new Inner(); i.setX( 100);
i = new Inner(); i.setX( 100); o.setY( i);
第10题:
300-300-100-100-100
300-300-300-100-100
300-300-300-300-100
300-100-100-100-100
第11题:
static final int[]a={100,200};
static final int[]a;static{a=new int[2];a[0]=100;a[1]=200;}
static final int[]a=new int[2]{100,200};
static final int[]a;static void int(){a=new int[3];a[0]=100;a[1]=200;}
第12题:
int[]ages=[100];
int ages=new int[100];
int[]ages=new int[100];
int()ages=new int(100);
第13题:
以下程序的调试结果为?
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}
}
A.输出结果 Outer
B.输出结果 Inner
C.编译错误,因Inner类定义为私有访问
D.在创建Inner类实例的行出现编译错误
第14题:
1. public class Outer{ 2. public void someOuterMethod() { 3. // Line 3 4. } 5. public class Inner{} 6. public static void main( String[]argv ) { 7. Outer o = new Outer(); 8. // Line 8 9. } 10. } Which instantiates an instance of Inner?()
第15题:
Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?() public class Q4a39 { int a = 1; int b = 1; int c = 1; class Inner { int a = 2; int get() { int c = 3; // insert statement here return c; } } Q4a39() { Inner i = new Inner(); System.out.println(i.get()); } public static void main(String args[]) { new Q4a39(); } }
第16题:
package foo; public class Outer ( public static class Inner ( ) ) Which statement is true? ()
第17题:
public class enclosingone ( public class insideone{} ) public class inertest( public static void main (stringargs)( enclosingone eo= new enclosingone (); //insert code here ) ) Which statement at line 7 constructs an instance of the inner class?()
第18题:
Consider the following class: class Test(int i) { void test(int i) { System.out.println(“I am an int.”); } void test(String s) { System.out.println(“I am a string.”); } public static void main(String args) { Test t=new Test(); char ch=“y”; t.test(ch); } } Which of the statements below is true?()
第19题:
Which two code fragments correctly create and initialize a static array of int elements?()
第20题:
Compilation fails.
An instance of the Inner class can be constructed with “new Outer.Inner()”.
An instance of the Inner class cannot be constructed outside of package foo.
An instance of the Inner class can be constructed only from within the Outer class.
From within the package foo, and instance of the Inner class can be constructed with “new Inner()”.
第21题:
c = b;
c = this.a;
c = this.b;
c = Q4a39.this.a;
c = c;
第22题:
The code runs with no output.
Compilation fails.
An exception is thrown at runtime.
ClassC is displayed.
第23题:
1
100
110
255