2017年最新java面试题及答案

发布时间:2017-02-17 00:00:00 编辑:小静 手机版

  class B {

  private int radius = 10;

  public void draw() {

  System.out.println(“B.draw(), radius = ” + radius);

  }

  public B() {

  System.out.println(“B constructor”);

  draw();

  }

  }

  public class A extends B {

  private int radius = 1;

  public void draw() {

  System.out.println(“A.draw(), radius = ” + radius);

  }

  public A(int radius) {

  this.radius = radius;

  System.out.println(“A constructor”);

  }

  public static void main(String[] args) {

  A a = new A(5);

  }

  }

  3、写出下列程序运行结果。

  public class Test {

  static Test st=new Test();

  static int x ;

  static int y=0 ;

  public Test(){

  x++;

  y++;

  }

  public Test(int x,int y){

  this.x=x;

  this.y=y;

  }

  public static Test getInstance(){ return st ;}

  static{

  int i=0;

  System.out.println(“i=”+i);

  }

  void test() {

  Inner inner2 = new Inner2();

  inner2.display();

  }

  public static void main(String[] args) {

  Test test1=Test.getInstance();

  test1.test();

  System.out.println(“test1:x=” + test1.x+”;y=”+test1.y);

下页更精彩:首页 上一页 1 2
本文已影响956
+1
0