首页 > 试题广场 >

阅读以下程序,写出输出结果。

[问答题]

阅读以下程序,写出输出结果。

class Plate {
  Plate(int marker) {
  System.out.println("Plate(" + marker + ")");
  }
  void f1(int marker) {
  System.out.println("f1(" + marker + ")");
  }
}
 
class Desk {
  static Plate plate1 = new Plate(1);
  Desk() {
  System.out.println("Desk()");
    plate2.f1(1);
  }
  void f2(int marker) {
  System.out.println("f2(" + marker + ")");
  }
  static Plate plate2 = new Plate(2);
}
 
class Board {
  Plate plate3 = new Plate(3);
  static Plate plate4 = new Plate(4);
  Board() {
  System.out.println("Board()");
    plate4.f1(2);
  }
  void f3(int marker) {
  System.out.println("f3(" + marker + ")");
  }
  static Plate plate5 = new Plate(5);
}
 
public class Initialization {
  static Desk desk = new Desk();
  Board Board = new Board();
  public static void main(String[] args) {
System.out.println("Creating new Board() in main");
    new Board();
    System.out.println("Creating2 new Board() in main");
    new Board();
    desk.f2(1);
    //Board.f3(1);
  }
}

Plate(1)
Plate(2)
Desk()
f1(1)
Creating new Board() in main
Plate(4)
Plate(5)
Plate(3)
Board()
f1(2)
Creating2 new Board() in main
Plate(3)
Board()
f1(2)
f2(1)
 

发表于 2017-05-17 16:37:30 回复(0)