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

Do I need to provide type hints for methods overriding `@abstractmethod`s?

Given these two classes: class MyClass(ABC): @abstractmethod def my_method(self, my_parameter: str): pass class MySecondClass(MyClass): def my_method(self, my_parameter): pass Does my_parameter in my_method of…
Mario Ishac
  • 5,060
  • 3
  • 21
  • 52
1
vote
1 answer

Python class inheritence isn't giving me separate instances of a list

I don't understand what is going on here. I have a class "C" that is a subclass of "B". "B" has an attribute "b" which is an instance of class "A". "A" has one attribute, a list called "a". When I initialize two different instances of "C", they have…
1
vote
2 answers

Subclassing, inheriting and subclass picking

I would like to build a class and subclasses where the subclasses inherit some methods and from the superclass. Nothing special so far, but I would like to be able to create subclasses depending on a parameter e.g. a = Shape(sides=3, base=2,…
qwertz
  • 46
  • 8
1
vote
2 answers

Python: pass whole self of class to init of new class

I have a class and a sub-class, I'd like to pass the whole of the self of the class to the sub-class. I can pass self over to the new class explicitly easily enough, e.g. class foo: def __init__(self, a, b): self.a = a self.b =…
1
vote
2 answers

The proper way to access the "self" property of a class

I have two objects i sub-classed from the str and int classes, to which i add a revert method, which can turn one object to the other: class newString(str): ... ... def revert(self, distance, obj): self = newInt(self) class…
Tochi Bedford
  • 354
  • 1
  • 9
1
vote
1 answer

How to share a variable among main and subclass in python?

(Not a profi programmer here, mine is probably a dumb question) I've a database stored in several ascii files (one file per table) within the same directory. I'm used to read all files and load each of them in Pandas DataFrame. Eventually I bundle…
Januz
  • 31
  • 2
1
vote
2 answers

Accessing Scanner objects from subclass in a superclass?

I am a very new, relatively inexperienced Java programmer. The project I am working is just a test of my current skills, and my goal is to write as efficient a program as possible. In essence, I have three classes: A, B, and C. B extends A and C…
ajent
  • 91
  • 1
  • 9
1
vote
3 answers

"Subscripted value is neither array nor pointer" error on BOOL in a subclass

I am getting the "Subscripted value is neither array nor pointer" error on a boolean made from another class that gets allocated in another. After looking up lots of reasons for getting this error, I'm not sure how I can relate it to mine. I'm…
Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
1
vote
3 answers

The constructor of an inner class of a superclass is undefined if there is argument in the super-constructor

I have a class A, and A_sub is an inner class of A. public class A { protected class A_sub { int A_sub_x = 1; A_sub parent; A_sub(A_sub obj_A_sub) { System.out.println("Constructor A.A_sub"); …
H42
  • 725
  • 2
  • 9
  • 28
1
vote
1 answer

Obj-C: Implementing delegate of custom subclass

In the ASIHTTPRequest documentation, it says: For more complex situations, or where you want to parse the response in the background, create a minimal subclass of ASIHTTPRequest for each type of request, and override requestFinished: and…
jrdioko
  • 32,230
  • 28
  • 81
  • 120
1
vote
0 answers

How to force subclass to implement setter (and getter) for an abstract property (in Pycharm)?

According to documentation (https://docs.python.org/3/library/abc.html), abstract setter (and getter) should be defined as: class C(ABC): @property @abstractmethod def my_abstract_property(self): ... …
user3225309
  • 1,183
  • 3
  • 15
  • 31
1
vote
2 answers

Custom UIView Implemenation

I have customView called BaseView which has a contentView, In the contentView I am adding all other subviews(UILabel, UIButton, etc) in the override init(frame: CGRect) method. Now I have 10 subclasses of my BaseView, which also overriding…
Ram
  • 269
  • 2
  • 9
1
vote
1 answer

Java interface design: where should I put a lot of duplicate code that will be used by all subclasses?

interface Tuple { void method1(); } class Tuple1 implements Tuple { @Override public void method1() { // some code .... utilityMethod(); // some code .... } // it will be used by subclasses of Tuple…
Guo
  • 1,761
  • 2
  • 22
  • 45
1
vote
1 answer

Abstract Class and Concrete Subclasses

I have two files: Validador.java and Peca.java. This is what I have in my Validador: public class Validador { public static void main(String[] args) { if(args.length == 0) { Peca p = new Rainha("t",1,2); }else if…
1
vote
1 answer

Is it possible in C++ to have a method in the superclass that when called by each subclass returns a shared_ptr to that subclass?

I want all children of a superclass to perform a similar action. So I figured I could have a method in the superclass to do so. The action requires sending a copy of (or shared_ptr to) itself as an argument to a method. But I do not know if such…
KMot
  • 467
  • 5
  • 13