Questions tagged [implements]

`implements` is a keyword in several programming languages used to denote implementation of an interface.

implements is a keyword in several programming languages which support OOP (such as Java or PHP) used to denote interface implementation (as opposed to extends used to denote implementation inheritance).

Related

404 questions
2348
votes
42 answers

"implements Runnable" vs "extends Thread" in Java

From what time I've spent with threads in Java, I've found these two ways to write threads: With implements Runnable: public class MyRunnable implements Runnable { public void run() { //Code } } //Started with a "new Thread(new…
user65374
  • 24,139
  • 4
  • 19
  • 7
810
votes
19 answers

Implements vs extends: When to use? What's the difference?

Please explain in an easy to understand language or a link to some article.
Saad Masood
  • 11,036
  • 9
  • 32
  • 40
259
votes
7 answers

What's the difference between 'extends' and 'implements' in TypeScript

I would like to know what Man and Child have in common and how they differ. class Person { name: string; age: number; } class Child extends Person {} class Man implements Person {}
davejoem
  • 4,902
  • 4
  • 22
  • 31
109
votes
5 answers

Extending vs. implementing a pure abstract class in TypeScript

Suppose I have a pure abstract class (that is, an abstract class without any implementation): abstract class A { abstract m(): void; } Like in C# and Java, I can extend the abstract class: class B extends A { m(): void { } } But unlike in…
Michael Liu
  • 52,147
  • 13
  • 117
  • 150
54
votes
3 answers

Interface extends another interface but implements its methods

In java when an interface extends another interface: Why does it implement its methods? How can it implement its methods when an interface can't contain a method body How can it implement the methods when it extends the other interface and not…
GingerHead
  • 8,130
  • 15
  • 59
  • 93
53
votes
2 answers

Why "extends" precedes "implements" in class declaration

Why must implement always be written after extend in a class declaration? For example: public class Register extends ActionSupport implements ModelDriven Why can it not be: public class Register implements ModelDriven extends ActionSupport The…
lzjun
  • 701
  • 1
  • 5
  • 8
48
votes
14 answers

Best way to implement View.OnClickListener in Android

Suppose we have an Activity with a lot of views on which OnClickListener is to be registered. The most common way to implement this is to let the Activity-Subclass implement the OnClickListener, something like this: public class ActivityMain extends…
Sarthak Mittal
  • 5,794
  • 2
  • 24
  • 44
45
votes
1 answer

extends and implements in one class in TypeScript

Can I do this in TypeScript? export interface IMyInterface { doSomething(): void; } export class MyBaseClass { myBaseClassHasProperty: string; constructor(){ this.myBaseClassHasProperty = 'some value'; } myBaseClassHasMethods(): void…
Everton Santos
  • 461
  • 1
  • 4
  • 5
40
votes
5 answers

How many interfaces can a class implement in PHP?

I'm looking for an answer to question which is not difficult, but I can't find out how many interfaces can be implemented by one class. Is this possible? class Class1 implements Interface1, Interface2, Interface3, Interface4 { ..... } For all…
Arnas Pečelis
  • 1,000
  • 2
  • 12
  • 32
39
votes
6 answers

extends class and implements interface in java

interface Bouncable{ } interface Colorable extends Bouncable{ } class Super implements Colorable{ } class Sub extends Super implements Colorable {} // Ok (case -1) But, class Sub implements Colorable extends Super {} // error (case -2) Why…
Ravi
  • 30,829
  • 42
  • 119
  • 173
32
votes
3 answers

Check if a generic T implements an interface

so I have this class in Java: public class Foo{ } and inside this class I want to know if T implements certain interface. The following code DOES NOT work but it's the idea of what I want to accomplish: if(T.class implements SomeInterface){ …
Budius
  • 39,391
  • 16
  • 102
  • 144
25
votes
4 answers

How to force implementation of a method in subclass without using abstract?

I want to force subclass to implement an implemented method of my mother class. I look this Java - Force implementation of an implemented method but i can't convert my mother class to an abstract class. public class myMotherClass { myMethod { …
Maniz
  • 415
  • 2
  • 7
  • 17
23
votes
2 answers

What's the difference between the implements & extends keywords in Java

What's the difference between the following keywords in Java: implements, extends?
sachin
  • 1,447
  • 4
  • 14
  • 22
21
votes
4 answers

TypeScript class implements class with private functions

I was exploring the possibility of having a class implementing a class in TypeScript. Hence, I wrote the following code Playground link: class A { private f() { console.log("f"); } public g() { console.log("G"); } } class B implements A { …
Radu Szasz
  • 981
  • 1
  • 9
  • 22
18
votes
2 answers

Behavior of strictfp keyword with implementing/extending an interface/class

JLS strictfp Interfaces specifies that : The effect of the strictfp modifier is to make all float or double expressions within the interface declaration be explicitly FP-strict (§15.4). This implies that all nested types declared in the interface…
Naruto Biju Mode
  • 2,011
  • 3
  • 15
  • 28
1
2 3
26 27