Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

WithoutBook Forum

Ques. what is interface in java?

- what is interface in java????????

Posted on Sep 22, 2010 by rajib biswas
Ans. Interfaces define a standardized set of commands that a class will obey
The commands are a set of methods that a class implements
The interface definition states the names of the methods and their return types and argument signatures
there is no executable body for any method - that is left to each class that implements the interface
Once a class implements an interface, the Java compiler knows that an instance of the class will contain the specified set of methods
therefore, it will allow you to call those methods for an object referenced by a variable whose type is the interface

To create an interface definition:
define it like a Java class, in its own file that matches the interface name
use the keyword interface instead of class declare methods using the same approach as abstract methods
note the semicolon after each method declaration - and that no executable code is supplied(and no curly braces)
the elements will automatica
Posted on Sep 22, 2010 by Arindam Ghosh

Ans. In Java Interface defines the methods but does not implement them. Interface can include constants.
A class that implements the interfaces is bound to implement all the methods defined in Interface.
Example of Interface:

public interface SampleInterface {
public void functionOne();

public long CONSTANT_ONE = 1000;
}
Posted on Sep 28, 2010 by Raj PR

Enter your Answer

Name
Email Address
Answer
©2024 WithoutBook