Questions tagged [inheritance]

Inheritance is the system in object oriented programming that allows objects to support operations defined by anterior types without having to provide their own definition. It is the major vector for polymorphism in object-oriented programming.

Inheritance is the main method by which object-oriented systems provide polymorphism.

Where a class Sub inherits from another class (or other object, as in Self or JavaScript) Base, Sub will share some or all of the operations (possibly including data access and storage) provided by Base. It is usually the case that Sub will receive at least the full public interface of Base in order to allow any object of type Sub to stand in place of an object of type Base in any code written to work on objects of type Base (refer to the Liskov Substitution Principle).

This facility is orthogonal to the type of type system used, the function binding regime (whether late or early), whether or not there is a privacy regime, or indeed the evaluation (whether lazy or weak).

Example of inheritance on a UML diagram:

enter image description here

See Inheritance on Wikipedia.

42250 questions
13
votes
3 answers

Calling a method of a super-super class

I'm having trouble accessing a method in a hierarchy when each class contains a method with the same name. class A { constructor(private name: string) { } notify() { alert(this.name) } } class B extends A { constructor() { …
Milo711
  • 265
  • 1
  • 3
  • 9
13
votes
1 answer

Why does method inheritance kill additional arguments?

I want to set some flags in my generic (before calling UseMethod(), I know that much :)), and then use and/or update these flags in the methods. Like so: g <- function(x) { y <- 10 UseMethod("g") } g.default <- function(x) { c(x = x, y =…
maxheld
  • 3,963
  • 2
  • 32
  • 51
13
votes
4 answers

Is it good practice to override non abstract methods?

I have a situation where I need to modify the super class method to have a subclass specific logic, but the methods logic is same for all other subclasses. I have two options: 1) make the method abstract and for each except my concerned subclass…
Learner
  • 569
  • 1
  • 5
  • 17
13
votes
3 answers

C++'s pure virtual function implementation and header files

I'm having some trouble implementing pure virtual functions inherited from some abstract class, when the classes in question are divided into *.h and *.cpp files. The compiler (g++) tells me that the derived class cannot be instantiated because of…
Neo
  • 1,176
  • 2
  • 10
  • 15
13
votes
2 answers

How to static assert in a member function only if it is used?

I have the following scheme: struct Baz {}; struct Qux {}; struct Base { virtual ~Base() {} virtual void foo() = 0; }; template struct Identity { static bool const value = false; }; template void bar(T) {…
101010
  • 41,839
  • 11
  • 94
  • 168
13
votes
3 answers

C# does not inherit the constructor from base class

Possible Duplicates: Constructors and Inheritance Why are constructors not inherited? When define class inherited from base class, I have to redefine all its constructors. I am wondering why C# does not support inherit from base class's…
user496949
  • 83,087
  • 147
  • 309
  • 426
13
votes
3 answers

C++: Accessing parent methods and variables

In which way should I access this parent method and parent variable? class Base { public: std::string mWords; Base() { mWords = "blahblahblah" } }; class Foundation { public: Write( std::string text ) { std::cout << text; …
user542687
13
votes
2 answers

Kotlin: How can a child constructor use its parent's secondary constructor?

For example, we have this parent: open class Parent(val id: Int, val name: String?) { constructor() : this(-1, null) } And a child, which must have both a two-param constructor and an empty constructor, like the parent: class Child(id: Int,…
Jire
  • 9,680
  • 14
  • 52
  • 87
13
votes
3 answers

What exactly does super() return in Python 3?

From Python3's documentation super() "returns a proxy object that delegates method calls to a parent or sibling class of type." What does that mean? Suppose I have the following code: class SuperClass(): def __init__(self): …
Asad Moosvi
  • 487
  • 5
  • 18
13
votes
2 answers

Default constructor for an inherited class

I've reduced my problem down to the following example code: class pokemon{ public: pokemon(int n); }; class MewTwo : public pokemon { public: MewTwo(int n); }; MewTwo::MewTwo(int n) {} Which produces an error: no matching…
Coltin
  • 3,744
  • 7
  • 31
  • 39
13
votes
6 answers

Way to specify multiple interfaces in Java

I have two interfaces, HasClickHandlers and DoesFancyFeedback. Then I have some UI objects that implement both interfaces - for example, a Button that implements both has click handlers and also does fancy feedback. In my code that's declaring…
Riley Lark
  • 20,660
  • 15
  • 80
  • 128
13
votes
3 answers

How to inherit a module from another module in Angular2?

So I'm using Angular 2 final (2.0.0) and let's say i create a WidgetsModule with a bunch of directives and components that will help me build my application, and then import it in my AppModule import { NgModule } from '@angular/core'; import {…
Pstr
  • 777
  • 1
  • 8
  • 17
13
votes
8 answers

Inherit from const class

I would like to inherit from a class with the const specifier like this: class Property { int get() const; void set(int a); }; class ConstChild : public const Property { // Can never call A::set() with this class, even if // the…
13
votes
2 answers

TypeScript: static properties and inheritance

I'm quite new to TypeScript (1.8) and I have a small issue with inheritance and static properties. Please find below the test code I'm currently running: class A { public static Items = { FOO: 'A' }; public show() { …
KorHosik
  • 1,225
  • 4
  • 14
  • 24
13
votes
1 answer

Why aren't OSGi Declarative Services (DS) annotations inherited from super classes?

The OSGi Declarative Services (DS) specifications define annotations which can be processed by tools, like Bnd, into the component description xml which is used at runtime. 112.8.1 in the R6 spec says: The Component Annotations are not inherited,…
BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
1 2 3
99
100