Hot Posts

Interfaces


Access Modifiers


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

  • Can ONLY extend multiple interfaces (not classes).
  • Cannot implement interfaces or classes.


Constructors


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

  • No return type allowed.


Blocks


Cannot define initializer blocks.


Members


Access modifiers: public
Non-access modifiers: static, final (implicitly public static final)

  • All members are public static final and cannot be anything else therefore it is not necessary to set the modifiers: public static final int I = 0; is the same as I = 0;
  • Can only declare constants and not instance variables;
  • Must be initialised.


Methods


Access modifiers: public
Non-access modifiers: abstract

  • All methods are implicitly public and  abstract, therefore it is not obligatory to set these key words;
  • Methods have no body e.g. public void abstract method();
  • Methods must be implemented/overwritten if the subclass is not an interface or an abstract class.

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.

private:

  • It does not make sense that interface methods are private as private methods cannot be inherited. The purpose of interfaces is that they are implemented/overwritten.


Behaviours


  • Interfaces cannot be instantiated.
  • Can be subclassed (extends) but only by interfaces/abstract classes;
  • Can be implemented (implements) but only by classes;
  • Only concrete classes must implement all methods i.e. non abstract classes;
  • Abstract classes that implement an interface are not required to implement the methods;
  • Interfaces are implemented by classes and extended by interfaces.

1 Trackback / Pingback

  1. Welcome « alex.theedom

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: