Questions tagged [extending-classes]

Method extending, in object oriented programming, is a language feature that allows a subclass or child class to inherit all the methods and properties of the extended class.

You can extend a class to provide a more specialized behavior.

A class that extends another class inherits all the methods and properties of the extended class. In addition, the extending class can override the existing methods. Overriding a virtual method allows you to provide a different implementation for an existing method. This means that the behaviour of a particular method is different based on the object you're calling it on. This is referred to as polymorphism.

A class extends another class using the extends keyword in the class definition. A class can only extend one other class.

Example in PHP

class Hello {
    public function message() {
        return "Hello";
    }
}

class HelloWorld extends Hello {
    public function message() {
        return parent::message() . " World";
    }
}

$class = new HellowWord();
echo $class->message(); //"Hello World"

In this example we the class Hello, and the function message.

Related tags:

100 questions
1
vote
0 answers

Can you extend an inner class in Kotlin, without extending it's outer class?

In Java you can do this: class Outer { class Inner { } } class ExtendedClass extends Outer.Inner{ ExtendedClass(Outer outer) { outer.super(); } } So I'd expect in Kotlin you write something like this: class…
1
vote
1 answer

Extending openpyxl workbook class

I would like to extend the existing capabilities of the openpyxl workbook class with custom made methods. I understand that normally I'd simply do so by defining my own class based on the original class class WorkbookExtended(openpyxl.Workbook): …
Midnight
  • 373
  • 2
  • 11
1
vote
1 answer

Can a member function be added to the Array class in JavaScript without showing up in a for-in loop?

In some code I'm working on I created a JavaScript function that is applied solely to Arrays, and I thought I'd try adding it as a member function. I added it like so: Array.prototype.myfunc = function(a){ ... } Which works fine for the most…
Jacob Ewing
  • 770
  • 7
  • 22
1
vote
1 answer

do extended classes inherit static var values (PHP)?

If I have a base class that contains a static var, I then set this static var, and then have a class that extends the base class, will the extended class retain the value of the static var that I have already set in the base class?
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
1
vote
1 answer

Javascript ES5: How to extend the Function object in order to set a property value on itself, every time the function is executed?

I currently have the following working code: Function.prototype.GetLastCallerName = function () { if (!this.arguments || !this.arguments.callee || !this.arguments.callee.caller) return null; var result =…
Arnie
  • 212
  • 1
  • 2
  • 11
1
vote
2 answers

Successfully pretty printing pandas.Series subclass with more than 60 elements

This is likely an easy fix, but I don't know how to do it. I have extended the pandas.Series class so that it can contain datasets for my research. Here's the code that I've written so far: import pandas as pd import numpy as np from allantools…
Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29
1
vote
0 answers

How to override class WC_cart?

How to override class WC_cart in class-wc-cart.php ? I trying: function action_woocommerce_add_to_cart($qqqq) { if ( ! class_exists( 'WC_Cart_new' ) ) { class WC_Cart extends WC_Cart_new { //my function ); $qqqq[] = new…
1
vote
3 answers

Scala conflict of types when extending a class

I have defined an abstract base class like following: abstract class Base() { val somevariables } And then, I extend this class like following: case class Derived (a: SomeOtherClass, i: Int) extends Base { //Do something with a } Then, I have…
taninamdar
  • 137
  • 1
  • 8
1
vote
3 answers

A way to extend existing class without creating new class in c#

I have a good complete class which is doing awesome things. I need to allow users to use this class by replacing some methods in it, but inheritance is not allowed, because this class also used in other application classes. It is like you have a…
Epsiloncool
  • 1,435
  • 16
  • 39
1
vote
1 answer

Define a class that extends Function

I'm trying to create a class that extends Function. var MyClass = class MyClass extends Function { constructor(func, /*some other things*/) { //this is not defined in extended classes for some reason var newThis = func; //assign other…
Sneaky Turtle
  • 191
  • 1
  • 11
1
vote
1 answer

Simplest way to extend Dashcode components?

I'm presently working on a project in Dashcode, and am getting increasingly frustrated at how the default classes have very little in the way of bind-able events much like jQuery uses. Dashcode doesn't let me edit the files, which I'm guessing is…
Li1t
  • 622
  • 6
  • 16
1
vote
0 answers

Cannot convert from

I have these four classes in DatabaseLayer: namespace DatabaseLayer { public class ReactionDoa { public int Id; public MessageDoa Message; public VisitorDoa User; public string Text; public DateTime…
yooouuri
  • 2,578
  • 10
  • 32
  • 54
1
vote
1 answer

Easiest way to call parent constructor

I am using an entity framework with a public ParentClass where the function does a lot of important things by searching configurations and DataBase entries and cannot edit this code as it is from a third-party. However I want to add extra “search”…
sugar
  • 11
  • 2
1
vote
1 answer

how do i extended 3rd party classes in cakephp?

I want to extend, not just create a new instance of a class I have sitting in my vendors directory. I googled and read the docs but I see no support for it. Can I do an app import of the 3rd party class, then write up the extended class followed by…
Angel S. Moreno
  • 3,469
  • 3
  • 29
  • 40
1
vote
1 answer

Problems with extending s.ds.am.UserPrincipal class

I have been trying to extend the s.ds.am.UserPrincipal class in VS 2010 VB app as I require access to AD User properties that are not by default a part of the UserPrincipal. This is a new concept to me and I have found some useful code on here as…