class A{ protected int i = 0;}
class B extends A{
public void Add(A a){
for(int i = 0;i<10;i++){
a.i++;
System.out.println(a.i);
} }
public void Add(){
Add(this); //this 作为一个对象传入,允许
//Add(super); //不允许 }
public static void main(String argc[]){
B b = new B();
b.Add(); }}

解决方案 »

  1.   


    class A{ protected int i = 0;}
    class B extends A{
    public void Add(A a){
    for(int i = 0;i<10;i++){
    a.i++;
    System.out.println(a.i);
    } }
    public void Add(){
    Add(this); 
    public static void main(String args[]){
    B b = new B();
    b.Add(); }}
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:  at B.main(B.java:11)
      

  2.   

    没什么打错,只是Add(this);  后面少了个},已经改好了,不过MyEclipse不是有提示哪编译错误吗?class A {
        protected int i = 0;
    }class B extends A {
        public void Add(A a) {
            for (int i = 0; i < 10; i++) {
                a.i++;
                System.out.println(a.i);
            }
        }    public void Add() {
            Add(this);
        }    public static void main(String args[]) {
            B b = new B();
            b.Add();
        }