Share on Google+Share on Google+

Interface in java

In this scjp tutorial you will learn about the interface.

An interface must be declared with the keyword interface. An interface is 100% pure abstract class that's mean an interface can have only abstract method, no concrete methods exists. A single class can implement many interfaces. Interface methods are by default public and abstract, you can explicitly declare these modifiers which is optional. Interface can have constants which are implicitly public, static and final and it declaration is optional in any combination. An abstract class can implement an interface. A class can able to extend only one class but it can implements many interfaces. An interface can extends one or more other interfaces. Interface cannot extends a class. Interface methods must not declare static. Interface have all methods abstract so it must not marked final, strictfp, or native.

The above concept can be viewed in examples provided in next page.

Interface Example-1
The motive of following code is that a concrete class can hold an interface and how to call that interface.
Interface Example-2
The motive of this example is that to show that interface can extend another interface.
Interface Example-3
The motive of this example is to show that a class can implement more than one interface
Interface Example-4
The motive of this example is to show an interface can extend another interface.


Posted on: July 1, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null