(6-10)有如下代码,请为指定位置选择正确代码。( )
class Outer{
class Inner{
void show() {
System.out.println("inner");
}
}
public void aOuterMethod() {
// ①
}
public static void main(String[] args) {
Outer out=new Outer();
// ②
Outer.Inner inn=out.new Inner();
// inn.show();
}
}
class Outer{
class Inner{
void show() {
System.out.println("inner");
}
}
public void aOuterMethod() {
// ①
}
public static void main(String[] args) {
Outer out=new Outer();
// ②
Outer.Inner inn=out.new Inner();
// inn.show();
}
}
举一反三
- 有如下类的定义,Inner类称为。 public class Outer{ class Inner{ public void go(){ System.out.print("hi"); } } }
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }
- public class Example { public static void main(String[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); } } class Father { public void show() { System.out.println("hellofather"); } }
- 下列程序运行结果是 public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- 有如下代码,则该程序运行时输出结果是。 class Test{ static int i=0; public void show() { i++; System.out.println(i); } } public class Demo { public static void main(String[] args) { Test test=new Test(); test.show(); } }