News Ticker

Abstract Classes


Access Modifiers


Access modifiers: package-default, public
Non-access modifiers: abstract (cannot be static/final)


Constructors


Access modifiers: private, package-default, protected, public
Non-access modifiers: none are allowed

  • No return type allowed.


Blocks


Access modifiers: package-default
Non-access modifiers: static or none


Members


Access modifiers: private, package-default, protected, public
Non-access modifiers: static, final, transient, volatile

  • If final must be initialized and cannot be volatile.


Methods


Access modifiers: private, package-default, protected, public
Non-access modifiers: static, abstract, final, native, strictfp

native:

  • Cannot have body code, looks like abstract method e.g. public native void method();
  • Must have return type void;
  • Cannot be strictfp;
  • Can have any other access and non-access modifier type.

abstract:

  • Only the access modifier can be set: package-default, protected, public (NOT private);
  • Cannot set non-access modifiers: final, native, strictfp, synchronized;
  • Has no body e.g. public void abstract method();

static/final:

  • Only non-abstract methods can be static/final;
  • It does not make sense that abstract methods are static/final as static/final methods cannot be overridden. The purpose of abstract classes is that they are implemented/overwritten.


Behaviours


  • Abstract classes cannot be instantiated.
  • Can be subclassed (extended) – subclasses must implement all abstract methods.
  • Subclass inherits non-abstract methods/members which can be overridden.
  • Implemented methods in subclasses can be synchronized even though the parent abstract method cannot be set as synchronized.

1 Trackback / Pingback

  1. Welcome « alex.theedom

Leave a Reply