本帖最后由 马林康 于 2012-6-22 11:53 编辑
1.- class A {
- public int i = 10;
- }
- class B extends A{
- public int i = 20;
- }
- public class TestPolm{
- public static void main(String args[]){
- B b = new B();
- A a = b;
-
- System.out.println(b.i);
- System.out.println(a.i);
- }
- }
复制代码 2- class A {
- private int i = 10;
-
- public void printI(){
- System.out.println(i);
- }
- }
- class B extends A{
- private int i = 20;
- }
- public class TestPolm{
- public static void main(String args[]){
- B b = new B();
- A a = b;
-
- b.printI();
- a.printI();
- }
- }
复制代码 3- class A {
- private int i = 10;
-
- public void printI(){
- System.out.println(i);
- }
- }
- class B extends A{
- private int i = 20;
-
- public void printI(){
- System.out.println(i);
- }
- }
- public class TestPolm{
- public static void main(String args[]){
- B b = new B();
- A a = b;
-
- b.printI();
- a.printI();
- }
- }
复制代码 我要的不是运行结果 ,我要的是解释
|
|