Home Help Java I The interface keyword
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

The interface keyword

Advertisement
In java programming language the keyword interface in java is used to declare and define an interface.

The interface keyword

     

In java programming language the keyword interface in java is used to declare and define an interface. Keywords are basically reserved words which have specific meaning relevant to a compiler. The keyword implement is used to implement an interface by a class. Interfaces in java are abstract means they can not be instantiated directly. Interfaces should be implemented by any class in order to instantiate them.

Syntex:  Here is the syntax that displays how to declare and define an interface.

[visibility] interface InterfaceName [extends other interfaces] {
 / constant declarations
  / member type declarations
  /  abstract method declarations
}

Note: Here are some points that must consider about an interface.

  • An interface in java includes only abstract methods i.e. methods have signatures only (or we can say, the methods with having their implementations).
  • An abstract type in java defines that it must be implemented by any class to make use of it.  
  • All the variables defined in java are constant variable i.e. the variables defined as final and static.
  • One benefit of using interfaces is they makes possible to achieve multiple inheritance since java does not allows multiple inheritance.
  •  All classes in Java must have exactly one base class, while java.lang.Object, is the exceptional case because it is the root class of the Java type system). 
  • Object references in Java should be bound to an object which implements the interface otherwise it may be specified to be of an interface type that must of null type. 
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: November 11, 2009

Related Tutorials

Ask Questions?    Discuss: The interface keyword   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com