Make visible what, without you, might perhaps never have been seen. - Robert Bresson
Tony Alicea
Desperado
Sheriff
Joined: Jan 30, 2000
Posts: 3219
posted
0
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
posted
0
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