implements and extends

I am confused when you use keywords "implements" and "extends". What is the major difference between these ?
[115 byte] By [Sangfroida] at [2007-11-26 17:14:52]
# 1
Implements is only used when there is an inheritance between a class and one or more interfaces.
govisagod512a at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 2
They mean the same thing--"inherits from". There is never a case where you have a choice of one or the other. Which one you must use depends on which two entities you're relating.class extends classinterface extends interfaceclass implements interface
jverda at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 3
Dont forgetclass extends class implements interface
duckbilla at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 4

Implements is a keyword used while using interfaces and eXtends is used while using inheritance.

For eg :

Interface Vehicle {

public String getEngine();

public String getHorn();

}

class Car implements Vehicle {

public String getEngine() {

return "Car Engine";

}

public String getHorn() {

return "Wolf Horn";

}

}

public class BMW extends Car {

public void myMethod() {

System.out.println("BMW CAR");

}

public String getEngine() {

return "BMW Car Engine";

}

public String getHorn() {

return "Air horn";

}

public static void main(String[] args) {

\\todo

}

}

Usually interface meant for generalization and inheritance meant for specialization.

The interface Vehicle is providing generic information regarding vehicle. But Car implements Vehicle and provides generic information about car. But BMW extends Car class and provide specific details about BMW.

AnanSmritia at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 5
> Implements is a keyword used while using interfaces> and eXtends is used while using inheritance.As I ponited out above, extends can also be used with interfaces, and both implements and extends signify inheritance.
jverda at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 6

> Implements is only used when there is an inheritance

> between a class and one or more interfaces.

No; it applies to methods declared with the same name and signature as a method declared in a superinterface or an abstract superclass.

[EDIT] Ah. I missed that the question was about the keyword interface. My apologies.

~

yawmarka at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 7

To ring the changes:

interface I {}

interface J {}

interface K extends I {}

interface L extends I, J {}

class C {}

class D extends C {}

class E implements I {}

class F extends C implements I {}

class G extends C implements I, J {}

Whew! That's the fastest nine types I've ever defined.

DrLaszloJamfa at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...
# 8

> To ring the changes:

Don't forget enum.

enum A implements I {}

enum B implements I, J {}

An enum cannot extend a class because it already implicitly extends Enum. A class cannot extend an enum because enums are final. But enums can implement interfaces (and in fact they implicitly implement Serializable to start with).

DrLaszloJamfa at 2007-7-8 23:42:51 > top of Java-index,Java Essentials,New To Java...