[Solved] This and super keyword usage in android


How can you call parent methods without “this” or “super” keyword?

You can without super provided that the method you call is not redefined in the “current” class, if it is redefined you may need to disambiguate the call:

class A {
  public void f() {}
  public void h() {} 
  public void i() {} 
}

class B extends A {
  public void g() { f(); } // same as super.f()
  public void h() { h(); /* recursive call */ }
  public void i() { super.i(); /* call to inherited but "masked" */ }
}

how are we able to call it without “this” or “super”?

this is not mandatory, when you write something in an instance method, it is read as this.something. This is why in the preceding example, the call h() is a recursive one.

this is not scoped, it denotes the “full” object itself. super scopes what follows. this is typed with the current class, and super is the object typed as its parent class.

solved This and super keyword usage in android