有如下类的定义,Inner类称为。
public class Outer{
class Inner{
public void go(){
System.out.print("hi");
}
}
}
public class Outer{
class Inner{
public void go(){
System.out.print("hi");
}
}
}
举一反三
- (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 A{ public void show() { show2(); } public void show2() { System.out.print("我"); }}class B extends A{ public void show2(){ System.out.print("爱"); }}class C extends B{ public void show() { super.show(); } public void show2() { System.out.print("你"); }}public class Test4 { public static void main(String[] args) { A a=new B(); a.show(); B b=new C(); b.show(); }} A: 我爱你 B: 爱你 C: 我爱 D: 我你
- 如下定义类的语法正确的是? A: public void 类名{} B: public static 类名{} C: public class 类名{} D: public class 类名(){}
- import java.io.*; class Person{ public void print(){System.out.print("Person ");} public void printMyGender(String s){ this.print(); System.out.print(s+" "); } } class Gender{ String type="gender"; public void print(Person p){p.printMyGender(type);} } class Female extends Gender{ public Female(){ type="female"; } } class Male extends Gender{ public Male(){ type="male"; } } class Employee extends Person{ public void print(){ System.out.print("Employee ");} } class Manager extends Employee{ public void print(){ System.out.print("Manager ");} } public class Test{ public static void main(String[] args){ Manager man = new Manager(); Employee em = new Employee(); Gender gender1 = new Male(); Gender gender2 = new Female(); gender1.print(man); gender2.print(em); } } 对于以上代码,其运行结果是
- Java程序如下 class A{ public A(){System.out.print("A");} } class B extends A{ public B(){System.out.print("B");} public static void main(String[]s){ new B(); } } 该程序将( )。