on 06-07-2007 9:23 AM
Hi all
when we talk abt an interface its said that the body of the interface consists of the method declarations only but no means of implementing them
what actually is that implementation part?
is that specifying the return type and the method parametres?
what actually are return type n method parametres
Thanks in advance
chaitanya.
Hai ,
interface is useful suppose u want change ur design in future suppose take
ex :
ur banking
u have loans like personal ,car loans
in future u want to put more loans facilities u can use those methods u just implement thats it ,
just for reusability purpose
thats it
k
bye
venkat p
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
good
As you've already learned, objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world; the buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to turn the television on and off.
In its most common form, an interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows:
interface Bicycle {
void changeCadence(int newValue);
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}
To implement this interface, the name of your class would change (to ACMEBicycle, for example), and you'd use the implements keyword in the class declaration:
class ACMEBicycle implements Bicycle {
// remainder of this class implemented as before
}
Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.
go through this link
http://www.cs.auc.dk/~torp/Teaching/E03/OOP/handouts/interface.pdf
thanks
mrutyun^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Krishna,
Interface consists of java code as that of class but with small difference. Interface will define only constant variables and abstract method. In interface none of the methods are implemented(Actual code is not written only definition of the method is done).All methods of interface are implicitly "public and abstract".Interface has the benefit of multiple inheritance. All the variables are implicitly "final static".
A class may choose to implement any number of interfaces. A class that implements an interface must provide bodies for all methods of that interface.
Arguments passed to the method are method Parameters.
Value in which method returns(Void, String, int.. etc) is return type.
Hope this helps,
Best Regards,
Lakshmi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi There
Java Objects define there interaction with outside world via exposed methods.
An interface will declare the method and a class implementing the interface will
have the actual method body.
method Parameters are the Arguments passed to the method
and Return parameter is the value which the method may return to the calling Object.
An interface will only specify the Method Name , Arguments and Return Type.
A Class will have to Implement the Interface and Have coding for the actual method.
In This way Different Classes can have Different Implementation of the Same
Method based on the Requirement.
For Example an Interface IShape may Contain the Declaration for CalculateArea.
Classes like Triangle and Circle can implement this method to suit their requirement. But what the outside world sees is just the CalculateArea Method
for both the Calsses.
Hope this Helps you.
Regards
Rajendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.