Questions tagged [extends]

extends is a keyword in several programming languages used to denote implementation inheritance

extends is a keyword in several programming languages which support object-oriented programming used to denote implementation inheritance (as opposed to implements used to denote interface inheritance).

Related

1708 questions
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
3 answers

Generics : List is same as List?

I am just trying to understand the extends keyword in Java Generics. List means we can stuff any object in the List which IS A Animal then won't the following also mean the same thing: List Can someone help me know the…
peakit
  • 28,597
  • 27
  • 63
  • 80
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
51
votes
8 answers

Java why interface extends interface

I am wondering under what circumstances do we extend an interface from an interface? Because, for example interface A{ public void method1(); } interface B extends A{ public void method2(); } class C implements B{ @Override public void…
peter
  • 8,333
  • 17
  • 71
  • 94
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
44
votes
3 answers

PHP - extended __construct

I was wondering if you could help me out.. I have two classes, one extends the other.. Class B will be extended by various different objects and used for common database interactions.. Now I would like class B to handle its connect and disconnects…
Lee
  • 5,816
  • 6
  • 45
  • 61
41
votes
3 answers

how to extend service with dependencies in angular 2

I have a parent service which has some dependencies like @Injectable() export class ParentService{ constructor(private http:Http, private customService:CustomService){} } and I want to extend the service @Injectable() export class ChildService…
Han Che
  • 8,239
  • 19
  • 70
  • 116
40
votes
3 answers

How to merge objects?

For instance, from these two objects : var object1 = { "color": "yellow", "size": null, "age": 7, "weight": null } var object2 = { "color": "blue", "size": 51, "age": null } I want this (object2 overrides object1 except for null…
TrtG
  • 2,778
  • 6
  • 26
  • 39
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
37
votes
2 answers

PHPUnit 6.1.x throws array_merge() error when my test class uses its own constructor method

I get this error: 1) XTest::testX array_merge(): Argument #1 is not an array ERRORS! Tests: 1, Assertions: 0, Errors: 1. On this test case: use PHPUnit\Framework\TestCase; class XTest extends TestCase { function __construct() {} …
Dennis
  • 7,907
  • 11
  • 65
  • 115
34
votes
2 answers

Extending Protobuf Messages

I have many different schemas, however there are a set of fields which every schema contains. I was wondering if there was a way to have a different schema extend a parent schema and inherit its fields. For example this is what I want: message…
user1413793
  • 9,057
  • 7
  • 30
  • 42
31
votes
4 answers

C++ equivalent of using for a java parameter/return type

In java, to make a function that returns an object that is the same type as a parameter and extends a certain class, I would type: public T foo(T bar) {...} Is there a C++ equivalent of this? In other words, how do I make a…
ricky3350
  • 1,710
  • 3
  • 20
  • 35
31
votes
2 answers

Hibernate @Embeddable class which extends another @Embeddable class, Properties not found for @OneToMany mapping

We are translating old xml based configuration to Annotation based configuration Situation There is a class which is annotated as @Embeddable(ParentPk.java), another class extends this class which is @Embeddable(ChildPk.java), this ChildPk.java is…
Yahya Arshad
  • 1,626
  • 2
  • 19
  • 34
24
votes
3 answers

Typescript Inheritance: Expanding base class object property

When extending a class, I can easily add some new properties to it. But what if, when I extend a base class, I want to add new properties to an object (a property which is a simple object) of the base class? Here is an example with some code. base…
Clorofilla
  • 415
  • 2
  • 6
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