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
3 answers

C1.bar() is executed, shouldn't it be C2.bar?

I have both these classes set up, as an example for learning the differences and uses of this() and super() however, the output is not as expected class C1 { protected void foo() { System.out.println("C1.foo()"); this.bar(); …
1
vote
3 answers

call method from subclass of UIImageview

I have two .m files. The first is the main code, The second is a subclass of UIImageView so that i can detect touches. In the main .m file I have added a progress bar and a customimageview both subviews of a scrollview. What I need is that when a…
sregorcinimod
  • 277
  • 3
  • 12
1
vote
1 answer

Custom button does not show title

I have customized an UIButton in Swift. But I cant get the title to display properly. This is my class : import UIKit final class CustomButton: UIButton { var cornerRs: Bool = false override init(frame: CGRect){ super.init(frame:…
Matias Barrios
  • 4,674
  • 3
  • 22
  • 49
1
vote
2 answers

Is there a way not to call the subclass method when invoking?

I wanted to create my own database program in Java. I know that there are already solutions out there like sylite etc., but I want to do it myself. As it turned out to be a more complex program than first expected, I used a lot of inheritance to…
1
vote
1 answer

How to make a subclassed, custom Django form field non-required?

The Django docs (http://docs.djangoproject.com/en/dev/ref/forms/fields/) say that you can create a subclass of django.forms.Field as long as it implements a clean() method and its init() method accepts the core arguments (required, label, initial,…
fieryred
  • 105
  • 1
  • 1
  • 8
1
vote
1 answer

Common type of Scala subclasses' runtime representation

I want to create a function that returns the runtime representation of Scala subclasses that have the same superclass using classOf, e.g. class C class C0 extends C class C1 extends C def f(i: Int): Class[C] = { if (i % 2 == 0) classOf[C0] …
bugfoot
  • 667
  • 7
  • 20
1
vote
1 answer

Setting non-optional properties in an SKShapeNode subclass

I am trying to create a simple SKShapeNode subclass which contains a label inside it. I've tried a couple of ways to do this but I get errors for both of them. Attempt 1 class MyNode: SKShapeNode { private var label: SKLabelNode init(_…
DanielGibbs
  • 9,910
  • 11
  • 76
  • 121
1
vote
0 answers

Solving system of linear equations in a subclass using inherited variables

I am trying to solve a system of linear equations in a subclass using inherited variables from multiple parent classes. The system contains 4 equations and 4 unknowns. Without including the long equations of what I'm working with, f(variable) means…
1
vote
3 answers

Deciding which subclass to instance at execution time

I have a Forum class with some subclasses, and I store the subclass name as a String field on a database along all other fields. When I retrieve the object, I want it to be an instance of the same class it was. I could do a lot of if-else statements…
1
vote
1 answer

Can I refer to subclass like parameter?

I would like to refer in my abstract class to any potential subclass like to parameter, to make universal functions, that would for example make new instances of subclass without overloading. abstract class Fictional { public static…
1
vote
2 answers

Compile error while subclassing std::optional

I'm trying to subclass std::optional in MS C++17 (VS2017) to add a message field to the class, but getting the compile error error C2280: 'OptMsg::OptMsg(const OptMsg &)': attempting to reference a deleted function Intellisense gives…
buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52
1
vote
1 answer

How to implement an arraylist from a superclass in the constructor of a subclass?

I'm currently trying to learn Java and I encountered a problem on which I'm a little stuck. I have one superclass and two subclasses that extend it, in the superclass I created an Arraylist that I want to use in the constructor of the subclasses…
pentaquark
  • 21
  • 7
1
vote
1 answer

Django - How to serialize inheritance

I walked through the documentation at https://django-model-utils.readthedocs.io/en/latest/managers.html to learn more about the InheritanceManager.I won't add the models.py because it is the same as in the documentation. So, here is my…
abdullah celik
  • 327
  • 2
  • 12
1
vote
3 answers

Making a utilities class for frequently used colors etc in app

I am making a utilities class that among other frequently used code have some methods for returning colors. However UIColor class is a part of UIKit so I wonder should I import UIKit to this subclass of NSObject, or should I return an id? Or are…
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
1
vote
0 answers

Why does an empty base class take space as a member variable?

As I understand it, Empty Base-Class Optimization (EBO) should take effect when my type derives from a base class that has no data members or virtual functions. Under GCC and Clang, this is not happening. Here is a sample: struct EmptyClass {…
cyberbisson
  • 382
  • 2
  • 9