• 2021-04-14
    已知类的继承关系如下: class Employee; class Manager extends Employee; class Director extends Employee; 则以下语句能通过编译的有哪些?
  • Employee e=new Manager();

    内容

    • 0

      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); } } 对于以上代码,其运行结果是

    • 1

      Which two demonstrate an “is a” relationship? () A:  public interface Person{}  public class Employee extends Person{} B:  public interface Shape{}  public class Employee extends Shape{} C:  public interface Color{}  public class Employee extends Color{} D:  public class Species{}  public class Animal (private Species species;) E:  interface Component{}  Class Container implements Component (  Private Component[ ] children;  )

    • 2

      class A class B extends A class C extends A 则以下语句能通过编译的是( )

    • 3

      已知类的继承关系如下: A: Employee e=new Manager(); B: Director d=new Manager(); C: Director d=new Employee(); D: Manager m=new Director();

    • 4

      已知类关系如下:ClassEmployee{}ClassManagerextendsEmployee{}ClassDirectorextendsEmployee{}则下列语句正确的是:()。 A: Employee e=new Manager(); B: Director d=new  Manager(); C: Director d =new Employee (); D: Manager m=new Director ();