implements

Does implements have the same effect as extending a class ? i'm not quite sure what is the different between the two of themthank you
[148 byte] By [Mike1988a] at [2007-11-26 20:07:45]
# 1
> Does implements have the same effect as extending a> class ? i'm not quite sure what is the different> between the two of them http://www.google.com/search?q=implements+vs+extends~
yawmarka at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 2

They both mean "inherits from." They're both a way to specify a parent-chld type relationship. In certain cases implements is the only correct syntax, and in other cases, extends is the only correct syntax. You don't get a choice of which one to use once you decide the class/interface permutation involved.

jverda at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 3
thx jverd.i wonder why does implement allows u to inher mutiple classes while extend allows only one class.
Mike1988a at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 4

> thx jverd.i wonder why does implement allows u to

> inher mutiple classes while extend allows only one

> class.

It's not an implements vs extends issue. It's an interfaces vs. classes issue.

class Class1 extends Class2, Class3 // not allowed

class Class1 extends Class2 implements Int1, Int2 // allowed

interface Int1 extends Int2, Int3 // allowed

jverda at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 5
> thx jverd.i wonder why does implement allows u to> inher mutiple classesInterfaces are not classes. http://java.sun.com/docs/books/tutorial/
dcmintera at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 6

You implement interfaces and extend classes. when you implement an interface you apply implementation to the methods in the interface. When you extend a class you inheret the methods from that class. You can only extend one class and you can implement multiple classes because that is how they developed java.

alien08o8a at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 7

We can inherit from multiple interfaces because interfaces don't allow implementation. Java allows multiple inheritance of interface, but not of implementation, so we can inherit from multiple interfaces (which have no implementation) but not from multiple classes (which might have implementation).

jverda at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 8
thx guys. If i understand it correctly mutiple interface could be extended and implemented but a class could only be extended and implemented one at a time? btw thx jverd for the simple code it helps alot :)
Mike1988a at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...
# 9

> mutiple

> interface could be extended

By another interface, yes.

> and implemented

By a class, yes.

> but a

> class could only be extended and implemented one at a

> time?

Extended, yes. A class cannot be implemented. There's no "implements SomeClass".

jverda at 2007-7-9 23:10:00 > top of Java-index,Java Essentials,New To Java...