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
0
votes
1 answer

Error while extending a C++ class (using the cocos2d-x framework)

So, I was following a tutorial from a book for an Android & iOS game. I am using cocos2d-x v2.2 on OS X 10.8 I came across a problem while extending the CCSprite class. Whenever I create an object from this class, the project stops running on…
wiseindy
  • 19,434
  • 5
  • 27
  • 38
0
votes
3 answers

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn't let me pass arguments to functions through event listeners, which makes me feel sad, so I need this property to exist on the event…
0
votes
2 answers

Split UIViewController implementation into multiple source files

I'm new to iOS development and I'm looking for a good example. Can someone give me a link? My problem: I made a project with some UIViewControllers, but I have a controller that has a lot of methods. How can I split my UIViewController into…
0
votes
2 answers

Extending views in backbonejs with requirejs

So I am using views that are sidebars that have tabs in them, so I created a parent class SidebarView from which I extend two new classes. LeftSidebarView and RightSidebarView. here is the parent class: define([ 'jquery', 'underscore', …
aledujke
  • 1,125
  • 7
  • 15
0
votes
1 answer

Stop parent function echo

Let's say in PHP you have a class Parent:
Crinsane
  • 818
  • 3
  • 16
  • 28
0
votes
1 answer

extending protected functions boost::python

I have C++ code (not mine, so it is not editable). Problem is with extending protected functions and class. #include "ExtraClass.h" ... MyClass::MyClass() { ... protected: bool Func{} ExtraClass m_Foo; ... } I need access in Python to m_Foo…
0
votes
1 answer

AS3:Instancing instances of classes

This is my problem: I have a Shared class which extends Main class. In my Shared class i am instancing other classes and adding them to this. class package { import flash.display.Sprite; public class Shared extends Main { public var m:Mirror =…
monolith
  • 1,606
  • 1
  • 12
  • 21
0
votes
3 answers

Yii Model extending / overloading

I have an Account Model which has some properties and relations, and i have an Reseller model. The point is that a reseller is actually an account only it has the possibility to have accounts beneath it. What is the best approach to implement…
TheWolfNL
  • 1,263
  • 1
  • 13
  • 29
-1
votes
2 answers

Can I extend an Oracle ADF (or any Java EE) war/ear without having access to the source?

There is a packaged application created in Oracle ADF (lets generalise and say any Java EE framework) that I would like to customise/extend. I want to make changes like add a new JSF page or modify a JSF page in there and change the data which…
Vampiro
  • 335
  • 4
  • 15
-1
votes
1 answer

prepare and execute in one method

I need PDO's prepare() and execute() in one method... but it doesn' work. Environment: IIS 10 / SQL Server 2014 class dbh extends PDO { ... public function xquery($sql){ if(($sth = $this->prepare($sql)) === false){ …
esviko
  • 250
  • 1
  • 3
  • 15
1 2 3 4 5 6
7