自己刚刚写的一段代码。结果出乎自己的意料 。
- package com.dzr.forty;
- class A{
- private int a;
- private int b;
- public A(){}
- public A(int a, int b){
- this.a = a;
- this.b = b;
- }
- public int sum(){
- return a+b;}
- }
- class B extends A{
- int a;
- int b;
- public B(int a,int b){
- super(1,1);
- this.a = a;
- this.b = b;
- }
- }
- class HEIMA {
-
- public static void main(String[] args){
- B b = new B(12,12);
- System.out.println(b.sum());
- }
- }
复制代码 |
|