Questions tagged [subclass]

A subclass is a class that derives or inherits from a parent (or super) class. Subclassing is used extensively in object-oriented programming (OOP).

A subclass is any class that inherits from a parent (or super/base) class. Depending on the language, a subclass will have a subset of the attributes and methods of the (parent/base) class from which it inherits. As a result, it is important to always tag a question with the language being used when tagging it with this tag

4137 questions
1
vote
1 answer

Should I not be subclassing the Cocos2d CCDirector class?

I'm trying to make cocos2d work as an RPG engine. I'm thinking of making a class that will coordinate the movements of the characters, the map loading/unloading etc. Should I make a CCNode for this, or just extend the CCDirector? Is there a reason…
Moshe
  • 57,511
  • 78
  • 272
  • 425
1
vote
2 answers

Pass an object as a list in subclass' constructor in python

How do I implement the Subclass B for the function getdata() to return the details in the constructor? I could achieve that if the constructor in B takes a single object, but having difficulty if the objects were two or more and passed as a…
K.Chams
  • 33
  • 5
1
vote
1 answer

Why can't I set some class properties directly?

This is probably some misconception on my side but I can't see why this doesn't work. I have created a UITableViewCell subclass, like this: class MenuCell: UITableViewCell { var mcImage: String var mcLabel: String init(mcImage: String, mcLabel:…
Alvaro
  • 182
  • 2
  • 13
1
vote
4 answers

how to call child method from parent reference?

I have a superclass called DataItem and it has multiple children and the children have children too. I dynamically set the object type but in the end the type reference is DataItem. Here is the code I use to determine the class type: private…
ikbal
  • 1,844
  • 4
  • 26
  • 46
1
vote
2 answers

Python str subclass represents a value which is not a real string

I am a novice in python. Working on extending an older module. So far it had a function that returned str (output of a blocking shell command). Now I need that function to also be able to return an object so later operations can be done on it…
Louis Shraga
  • 773
  • 1
  • 7
  • 26
1
vote
2 answers

How do I change the __lt__ magical method so this algorithm can work ? - Python

Python Sorting Problem I have a sorting algorithm problem, that consists in sorting objects of sublclass Priority Person(this objects will be placed in a list and the goal is to change the lt method of the subclass priority person to have a…
1
vote
3 answers

How to call a subclass method from super's associated class

Imagine I created two associated classes (Building and Person). A building can accommodate n people (persons) and a person can only be in a building at a time. The code (just the relevant part of it) so far is: public class Building { //some…
Alberto
  • 15
  • 1
  • 6
1
vote
1 answer

Subclass Variables are Undefined - js

I am programming a game and am having trouble with variables and inheritance, whenever I try to access them in the inherited class they come up as undefined. I have tried using super to help with the problem but that has not worked, this may be…
1
vote
2 answers

How to do a callback from super class to subclass in dart

I have an abstract class that adds strings to a list and does some other stuff. abstract class Abc { final _list = []; Function(String) addedValue; void add(String s) { _list.add(s); if (this.addedValue != null)…
pauleohare
  • 209
  • 2
  • 8
1
vote
1 answer

Python why does issubclass(int, float) return False

In Python, why do both issubclass(int, float) and isinstance(1, float) return False? I always thought that int is a subclass of float. In [1]: issubclass(int, float) Out[1]: False In [2]: isinstance(1, float) Out[2]:…
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
1
vote
2 answers

Is it possible to assign an instance of a subclass to a variable of a superclass?

I am confused as to the definitions and the logistics behind the superclass and subclass.
boboz
  • 19
  • 1
1
vote
4 answers

PyQt: how to receive keyboard events in a subclassed QWidget?

Maybe this is been asked many times, but i can't find a solution. I have a dialog: class PostDialog(QtGui.QDialog): def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.ui = Ui_Dialog() #code from…
apelliciari
  • 8,241
  • 9
  • 57
  • 92
1
vote
2 answers

Javascript Class and extend

I don't quite know how to phrase this so I'll just dive ahead and try to explain it as best as I can. I don't quite know how to store class properties without using them, or something like that. If we have a class of Message that contains a method…
Nick09
  • 206
  • 2
  • 15
1
vote
2 answers

Rails 3 model subclasses driving me CRAZY! Please help with correcting urls/params hashes

I have a problem with subclassing Rail's models. Suppose you have a User model and several subclasses of it (user types) that store specific methods and associations, for example: Director, Admin, Trainee, Instructor, etc. This is just simple…
Fire Emblem
  • 5,961
  • 3
  • 24
  • 37
1
vote
1 answer

How do you call subclass method in superclass, in Java?

I am planning on coding an API. I want to call a method from the API super class, that will be declared in the class that extends the API class. Is there a way to do this? Thanks - PrimeCubed
MisterHazza
  • 188
  • 1
  • 10