can the keyword 'this' be used in an abstract class in java

Posted by Reddy on Stack Overflow See other posts from Stack Overflow or by Reddy
Published on 2010-06-09T07:03:04Z Indexed on 2010/06/09 7:22 UTC
Read the original article Hit count: 190

Filed under:
|

I tried with below example, it is working fine.

I expected it to pick sub-class's value since object won't be created for super class (as it is abstract). But it is picking up super class's field value only.

Please help me understand what is the concepts behind this?

abstract class SuperAbstract {
  private int a=2;
  public void funA() {
    System.out.println("In SuperAbstract: this.a "+a);
  }

}

class SubClass extends SuperAbstract {
  private int a=34;
}

I am calling new SubClass.funA();

I am expecting it to print 34, but it is printing 2.

© Stack Overflow or respective owner

Related posts about java

Related posts about abstract-class