August 02, 2011

Interface in Java

  • In real world, Interface is nothing but thing which acts as connection between two objects.
         For example,
                Power button acts as an interface between Human and Computer.
  • In Java,Interface is created by using the keyword interface.
  • The interface name can be start with letter I, which is used to identify that the particular block is an Interface.
  • In interface, we can only declare variables and methods.
  • The initerface is implemented in a class by using the keyword implements (Refer Syntax)
  • The variables declared in interface are by default "public and final" .
  • The definition part of the method should lies in the class that implements the particular interface and the method should be declared as public.
  • A class can implement any number of interfaces and it is used to achieve multiple inheritance in java.
Syntax:

           interface Interfacename
           {
               
                //Variable and Method declaration
            }

           class Classname implements Interfacename
          {
               //Definition for methods in Interface
           }

No comments:

Post a Comment

Connecting Java program to Database

It is very simple to establish a connection to the Database from a Java program          Class.forName("com.mysql.jdbc.Driver...