File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces" Watch "Interfaces" New topic
Author

Interfaces

S.Hamid
Greenhorn

Joined: Dec 28, 2001
Posts: 4
How Interface realize that which class use its methods.


No Path of Flowers Lead to Glory
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
by Polymorphism?? no? maybe i don't understand your question.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

If I understand the question correctly, an interface does not maintain state information, and therefore doesn't "know" when it's being used.

------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
My sentiments exactly
A class is made to implement an interface. That just means that the class must have methods with the right signature and return type (the return type is not part of the signature) as dictated by the Interface.
As this is the beginner's forum, a class can only inherit from one class but it can implement many interfaces.
Poors man's "multiple inheritance"


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Tony Jackson
Ranch Hand

Joined: Feb 23, 2001
Posts: 45
I'm also not sure of your question, but I will explain some things about Interfaces and Classes and Objects with the hope of clarifying things for you.
First, let's say you have an interface called "Drawable" that defines a method drawToScreen:
public void drawToScreen();
(this method presumably draws the object on the screen.)
Second, say you have two or more classes that implement Drawable, including "Square", "Circle", and "TextBlock".
Third, your program calls a static method "nextObject()" that gets a Drawable object and you then want to draw it on the screen.
You write the following code to get the object and draw it on the screen:
Drawable d = someClass.nextObject();
d.drawToScreen();
One key point is this: you are doing all this (getting an object and calling one of its methods) without ever knowing what kind of object it is. The object d might be a Square, or a Circle, or something else. Whatever it is, you know it implements the interface "Drawable" and thus that it has the method "drawToScreen()".
If you really wanted to know what kind of object d was, you could use this:
Class c = d.getClass();
String s = c.getName();
Tony Jackson
------------------
Tony Jackson
Trainer and Courseware Developer
tjackson@selectica.com
 
wood burning stoves
 
subject: Interfaces
 
Similar Threads
Home interface or Home Interface stub
How To Call Two Different Classes From the Main Program Using the Same API?
interface extends interface ?
Writing an Interface
Time Capsule