Hey there! any question in your mind? Ask It Now!.

Popular Categories





Interface in java and use of interface

+5 votes
73 views
asked in Programming by amit (370 points)
I want to know about interface in and what is the use Or benefits of it with examples.
 Hope you will help me.
Thanks for help!

2 Answers

+2 votes
answered by amit_pammu Expert (5,030 points)
selected by amit
 
Best answer

An interface in Java is similar to a class, it  include only abstract methods and final fields (constants). A class implements an interface by providing code for each method declared by the interface.

Here’s a basic interface that defines a single method, named Playable, that includes a single method named play:

public interface Playable
{
    void play();
}

how to use it:

  • It must specify an implements clause on its class declaration.

  • It must provide an implementation for every method declared by the interface.

example :

public class TicTacToe implements Playable
{
    // additional fields and methods go here
    public void play()
    {
       // code that plays the game goes here
    }
    // additional fields and methods go here
}
commented by amit (370 points)
Thanks sir for giving such a valuable information.
0 votes
answered by user8080 (590 points)

actually interface work as a medium.. which intract the user with the hardware or software .!

in java ..as you know JAVA does not support the multiple inheritance .so we use INTERFACE for the multiple inheritance..!

 

Related Questions

0 votes
1 answer 99 views
0 votes
0 answers 77 views
+8 votes
2 answers 132 views
0 votes
0 answers 73 views
0 votes
0 answers 181 views
asked in Programming by vimal jain
0 votes
0 answers 100 views
0 votes
1 answer 127 views
+1 vote
1 answer 875 views
+3 votes
1 answer 768 views
+2 votes
2 answers 799 views

Not a Member yet?

Ask to Folks Login

My Account
438 Folks are online
2 members and 436 guest online
Your feedback is highly appreciated