Interface

Ads
 

Interface

Can Any one Give the exact program explanation for Interface in java? and want to know why they used interface instead of multiple inheritance? Thanks in advance

View Answers

August 24, 2012 at 11:52 AM

An interface is one which has abstract methods(not defined just declared)and static or non static variables.Any class can implement(inherit)the interface and make use of the methods(functions) and variables within it.

Here is an example where we have defined an interface and implements its methods (which are declared in interface) int the class.

interface Ex{

int getData();

void setData(int x);

}
class InterfaceExample implements Ex 
{
    int x;
    public int getData(){
        return x;
    }
    public void setData(int x){
        this.x=x;
    }
    public static void main(String[] args) 
    {
    InterfaceExample ex=new InterfaceExample();
    ex.setData(5);
    int num=ex.getData();
    System.out.println(num);
    }
}

Actually java does not support multiple inheritance. The reason behind this is when we extends more than one class, JVM get some ambiguous problem and will get confused as which method it will take.It creates complexity.Therefore java uses Interface.

Ads









Related Tutorials/Questions & Answers:
interface
interface   what is the use of marking interface
interface.
interface.  Write short note on interface.   Please visit the following link: Java Interface
Advertisements
interface
interface  will the interface implements a interface   Hi Friend, No. Interface can extends another interface but cannot implements it, because interface will not contain the implementation. Thanks
INTERFACE
INTERFACE  how interface support multiple inheritance in java
interface
interface   Hi I have interface in that interface 3 methods are there , after some days client said that,i want to add one more method in that interface ,so how can add 4 method so that the implemented class did not affect
interface
interface  can we extend interface?   Hi Friend, Yes an interface can be extended by other interface like using extends keyword interface A{ } interface B extends A{ } For Example: interface IntefaceA { void
interface
interface  what the use of interface?   An interface is one... variables.Any class can implement(inherit)the interface and make use... is achieved by using the interface (by implementing more than one interface at a time
interface
interface  What is marker interface ?? what is its use in java programming?? is this us in programming ??Explain is implementation with code
interface
interface  develop a library interface which has drawbook(),returnbook()(with fine),checkstatus() and reservebook() methods.all the methods tagged with public
interface
interface  develop a library interface which has drawbook(),returnbook()(with fine),checkstatus() and reservebook() methods.all the methods tagged with public
Interface
for Interface in java? and want to know why they used interface instead of multiple inheritance? Thanks in advance   An interface is one which has abstract... implement(inherit)the interface and make use of the methods(functions
interface
interface  why do we need interface in java..if it`s usefull for to obtain multiple inheritance in the sense how it gonna be achieved...and i can...)...the y we need interface...THis is question often i heard from my developer
Interface
Interface  I need to implement the interface without overriding its method and also don't use abstract class for this. How to do
interface
interface  What is the exact use of interface in real time scenario? some people says that interface provides multiple inheritance. Is it true...; Through interface, we can achieve the multiple inheritance. Java does
Interface
Interface  1.Create an interface names ShapeInterface that has two... class a.Rectangle that uses the interface b.Circle that uses the interface and abstract class   interface ShapeInterface{ int l=0,b=0; public
Interface
Interface  1.Create an interface names ShapeInterface that has two... class a.Rectangle that uses the interface b.Circle that uses the interface and abstract class   interface ShapeInterface{ int l=0,b=0; public
Interface
Interface  Declare an Interface called property containting a method compute price to compute &return the price.The inerface is to be implemented by follwaing two class (1)Bungalow&(2)Flat both the lasses have following
Can an Interface extend another Interface?
Can an Interface extend another Interface?   Hi, Can an Interface extend another Interface? thanks
Can an Interface implement another Interface?
Can an Interface implement another Interface?   Hi, Can an Interface implement another Interface? Thanks
Interface implimentation
Interface implimentation  How to impliment an interface For Achieveing MVC & loosCupling in Any Project
callable interface
callable interface  When we use the callable interface instated of runable interface
logfile interface
logfile interface  How to create logfile interface for programs in java
Marker interface
Marker interface  what is a marker interface? what is its significance
Abstract and Interface
Abstract and Interface  what is the difference between Abstract and Interface accurateatly
null interface
null interface   what is the null interface and what is the use of it in real java project ?   Hi Friend, A null interface is an interface without any methods.Is also known as Marker interface. Null interfaces are used
interface_querry
interface_querry  By using interface we have to implement all unimplemented methods into our class, even though we are not using all of methods, what is the alternative
Interface in java
Interface in java  An Interface method implemented in more than one different class with same method name. To avoid overriding of methods, we use ObjectReference for that class
Marker Interface
Marker Interface  What is the need of Marker Interface?When should we use
Abstract and Interface
Abstract and Interface  What is interface? When time is most suitable for using interface? Why we use interface instead of abstract? What is the differences between abstract and interface?   An interface defines a set
Markable Interface
Markable Interface  In Java can we create our own Markable Interface?? If yes then how, Please explain with example   Marker interface...) the state of an object then you have to implement the Serializable interface
Interface in javascript
Interface in javascript  Implement an interface in javascript, which takes in a collection of objects, and the column names on which we should build indexes ( say a simple BST) and defines the "where" query functionality

Ads