Home > Chinese - 中文 > Polymorphism/inheritance pop quiz about Java

Polymorphism/inheritance pop quiz about Java

October 14th, 2009 Bali Leave a comment Go to comments

前面几篇都是关于THINK的。Well,动动嘴皮子总是很容易的,虽然在某些情况下吹牛也是一项必备的技能。其实,我一直很hands-on,而且enjoy hands-on, 每天都写code。也许我哪天做了CEO还是会写的,就因为喜欢。听说Intel SSG的前老大叫(什么什么来着),一人之下的位子,兴致来了,还会连上debugger,帮你调程序,呵呵。

好,上code,开始ACT。有两个class A, B,B is inherited from A. 问在下列几种情况下,会出现什么结果,并解释为什么。

public class B extends A {

      public int foo(int t) {

            return 0;

      }

}

(1)

public class A {

      public void foo(int t) {

            return;

      }

}

(2)

public class A {

      public int foo(int t) {

            return 1;

      }

}

(3)

public class A {

      private int foo(int t) {

            return 1;

      }

}

(4)

public class A {

      public int foo(int t, int s) {

            return 1;

      }

}

尤其是将要面试的同学,如果这个东西还没搞清楚,那么…除非你算法很强。另外,哪位同学知道,如何贴code吗?格式要保持Eclipse那样,非图片。

Categories: Chinese - 中文 Tags: ,
  1. No comments yet.
  1. No trackbacks yet.