jam
发贴: 79
积分: 30
|
于 2003-06-17 16:30
class A { int i = 1; int f() { return i; } static char g() { return 'A'; } }
class B extends A { int i = 2; int f() { return -i; // ----- -i not -1 , sorry } static char g() { return 'B'; } }
public class Test { public static void main(String args[]) { B b = new B(); A a = (A) b; System.out.println(a.i); // 1 ------------ can use ? to explain System.out.println(a.f()); // -2 ------------ can use 'polymorphism' to explain System.out.println(a.g()); // A ------------ can use ? to explain System.out.println(A.g()); // A ------------- can use 'static' to explain } }
I had been post before. I was uncertain of reason.
jam edited on 2003-06-17 18:44
|