- class A
- {
- public double y=11.456789;
- public void f()
- {
- this.y=this.y+1;
- System.out.printf("y=%f\n",this.y);
- }
- }
- //相当于
- class B extends A
- {
- int y = 0;
- public void g()
- {
- this.y=this.y+100;
- System.out.printf("y=%d\n",y);
- }
- //相当于子类中有这样的方法,继承过来的
- public void f()
- {
- super.y=super.y+1;
- System.out.printf("y=%f\n",super.y);
- }
- }
- public class Example {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- B b =new B();
- b.y = 200;
- b.g();
- b.f();
- }
复制代码
|