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).
4,005
questions
0
votes
4
answers
40
views
java - class attribute type change with inheritance
I have a MyClass which has an attribute of type MyAttribute.
This class is inherited by MySubClass which has an attribute of type MySubAttribute.
MySubAttribute is a subclass of MyAttribute :
class ...
-1
votes
1
answer
30
views
using private variable of a class in a methode of a subclass
public class B {
private int y ;
public B(int y){
this.y = y;
}
public int gety(){
return y;
}
}
public class C extends B{
int y,z;
public C(int y, int z ...
-1
votes
2
answers
23
views
Why isn't my subclass inheriting a method from the superclass?
In a blackjack game I have the following piece of code:
class Hand(object):
def __init__(self):
self.hand = []
def hand_score(self):
...
class ...
0
votes
0
answers
16
views
How does matchit subclass look so complicated?
I am trying to match test/control using a string that concatenates different values (for example: 1_4_5). I ran matchit using exact matching for the variable above and mahalanobis for 2 or 3 other ...
2
votes
1
answer
43
views
How to restrict enums in Kotlin?
I have an enum with many values; error codes for example, or some official list of coded values. In my application, I have several functions where only a subset of those values is admissible. How can ...
1
vote
0
answers
45
views
Mapstruct mappingTarget with subclasses
I'm using new feature in mapstruct to map hierarchy of classes. And now I need to write rest PUT for update. But it actually not updating fields of subclasses, and I could not apply any mapping ...
0
votes
1
answer
28
views
Cast an Object to its superclass in Java
Learning Java here and I try to cast on a super class and i cant access to subclass methods, is it possible, I am doing something wrong.
I have this:
public class Musician {
public String ...
0
votes
1
answer
51
views
Java subclass initialize with arguments of superclass
I'm new in java (started 2 weeks ago) and I've been making some random challenges I found on internet. My current problem is that when I access to an override method in any of my subclasses (Tablet ...
0
votes
0
answers
40
views
create arrayList including attribute from superclass and subclass
please help me
I have to create a 4 function using switch method. And I have a problem with function 3(show list of video and song)
For more details, I suppose I should create a class likes ...
0
votes
0
answers
19
views
TypeError: Can't instantiate abstract class <...> with abstract methods - when subclassing another class that implements the abstract method [duplicate]
I have multiple abstract classes that defines an API for something called say SemiMarkovianGraph and MarkovianGraph. These two have the following inheritance:
class MarkovianGraph(metaclass=ABCMeta):
...
-1
votes
0
answers
28
views
Not able to understand the overloading with super class and sub class [duplicate]
**class A {
}
class B extends A{
}
public class App
{
public void show(B o) {
System.out.println("Object");
}
public void show(A o)
{
System....
2
votes
1
answer
51
views
How to type-hint that container subclass always contains particular type?
I'm struggling to get type-hinting to work as I would expect regarding the content types for custom container subclasses in PyCharm. Let's start with a case that works as I would expect. You can ...
0
votes
1
answer
21
views
How to create a subclass with different default values that can still be changed?
I would like to create a subclass of the Text class in this animation library I am using. I would like this subclass to have a different default font size, color, opacity, and stroke width than the ...
0
votes
2
answers
38
views
Flutter: Superclass variable to upper case without touching subclass
Here i have some pseudo code with this scenario.
The UpperCaseElement superclass has the text variable. If upperCase is true, the text variable should be turned into upperCase.
I have tried setting it ...
0
votes
0
answers
43
views
java generic method overload by subclass
Though Mybatis LambdaQueryWrapper nothing to do with this question, my example may need it to describe my question.
My Class is basicly like this.
public class TestA {
private String name;
...
1
vote
3
answers
63
views
c++ subclass access functions of parent class
I have the following Class structure:
class WiFiHandler{
public:
void doWiFiStuff();
};
class Machine {
public:
void doSomething();
WiFiHandler _wifiHandler;
};
Now ...
-3
votes
1
answer
41
views
Why is the superclasses field different when called from subclass?
Why is field nodes returning different size when called from subclass
shouldn't subclasses have access to their super classes fields?
Here is reproducible example:
Manager.java
import java.util....
0
votes
1
answer
40
views
Import files that are not known before the execution (Python)
In my project I have a generic class named Interface and many subclasses which inherit from Interface:
/interface_folder/
interface.py
interface_a.py
interface_b.py
interface_c.py
...
/test/
test....
0
votes
1
answer
32
views
Python can't infer static type of subclass when using a handler factory
I would like to use a general HandlerFactory class like the one described here (see Solution 2: Metaprogramming).
Let me use an example:
Suppose we have the following classes:
class Person:
name: ...
0
votes
1
answer
29
views
Extending EventEmitter class of react-native fails with `Super expression must either be null or a function`
I have followed the examples for ES6 here.
https://ourcodeworld.com/articles/read/445/how-to-use-event-emitters-with-es5-and-es6-in-node-js-easily
My code:
import {EventEmitter} from 'react-native';
...
-1
votes
3
answers
76
views
C# create iterable list of settings with different data types
I am pulling my hair out on this one. It seems so simple but it's not. I just want to create a simple list of settings. Each setting has a "name", "value" and "default"....
0
votes
0
answers
32
views
Changing type argument of Python with subclassing
Python's typing system allows for generics in classes:
class A(Generic[T]):
def get_next(self) -> T
which is very handy. However, even in 3.11 with the Self type, I cannot find a way to ...
0
votes
0
answers
22
views
Unable to override Greenlet.__init__function when gevent APIs are invoked
I am trying to override the Greenlet.init function inside the gevent package. The purpose is to maintain a list of all greenlets that are running and whose current backtrace can be dumped.
I can do ...
0
votes
2
answers
57
views
How to filter a realm subclass swift
How do I filter a subclass in realm for swift?
I have a realm class "SubscriptionClass":
class SubscriptionClass: Object {
@Persisted(primaryKey: true) var subscriptionId = "" //...
0
votes
0
answers
25
views
Inheritance Question: Question 9 on AP Computer Science A Barron's Book; subclass modifying parent class?
These are the three classes (1 parent, 2 subclasses)
public class BankAccount
{
private double balance;
public BankAccount()
{ balance = 0; }
public BankAccount(double acctBalance)
...
0
votes
2
answers
32
views
Why is my object render function displaying None?
So I'm currently building a Html rendering program in Python which uses two base classes:
SingleTag - Used for tags that don't have any children such as a tag
ContainingTag - For tags that have ...
0
votes
3
answers
53
views
In Java can we create an object of a subclass in the subclass itself and outside the methods of the subclass?
I need to create an object of a subclass in the subclass itself but outside of all the methods of the subclass.
In the code below, I want to create an object of ODrawPanel at the specified location (...
0
votes
1
answer
55
views
how to disable move construct base class from derived class?
In the following code, I want to disable the move construction of base class Vector from derived class VectorMap, and call the copy constructor.
#include <iostream>
#include<algorithm>
...
0
votes
0
answers
35
views
Casting a superclass object into a subclass object in java
public VIPCustomer getRealVIPCustomer(String ID) {
VIPCustomer vipCustomer = new VIPCustomer(ID);
for (Map.Entry<String, Customer> vipCustomerCheck : allCustomers.entrySet()) {
...
0
votes
0
answers
25
views
How to mock exported non-static subclasses with jest
I've node module with class like this (file MYClient.ts):
export default class MYClient {
private epURL: string;
constructor(epURL:string) {
this.epURL = epURL;
}
public one = new (...
0
votes
1
answer
19
views
How to pickle a subclass instance if super (from fixed library) rejects it?
I'm subclassing logging.Logger and although I'm implementing __getstate__ very safely, I get an error by the superclass saying you cannot pickle this. How to get around this?
Minimal reporducible code:...
-1
votes
1
answer
31
views
Using a Subclass to use as parameter
public class Animal {}
public class Cow: Animal {}
public class JerseyCow: Cow {}
Hello. So, I want to be able to pass a Subclass/Type as a parameter so that the method below works. After ...
1
vote
1
answer
39
views
How to print sub-class name in pydantic?
I used pydantic to define a class. I created a sub-class inherent from a parent class. When I print sub-class, why does it still show the parent class name? What should I do to print Word class?
class ...
0
votes
0
answers
11
views
Subclass CLlocation error, Use of unimplemented initializer
I'm try to create Subclass of CLLocation in order to be able to make some calculation on the location I retrive from GPS
i have create the following class
class CalculateLocation : CLLocation {
...
0
votes
3
answers
38
views
Purposely trying to break Python class inheritance, don't understand why it breaks this way
I'm exploring the limits of Python class inheritance, so I wrote a small test to see how much I can get away with - redeclaring properties and overriding functions.
class A:
val : int = 3
def ...
0
votes
1
answer
58
views
Creating a subclass and object at the same time
I am looking for a C# equivalent of a Java idiom.
In Java, if you have an abstract class, you cannot directly create an object of that class; you need to subclass it (and provide an override of the ...
0
votes
0
answers
22
views
Subclassing numpy.ndarray problem with method
I am subclassing numpy.ndarray in the following way:
import numpy as np
class NewSubclass(np.ndarray):
def __new__(cls):
obj = np.asarray([]).view(cls)
obj.period = None
...
0
votes
0
answers
12
views
creating a superclass object by using subclass' constructor
let's say we have a superclass Person and a subclass Child, I'm ok that
Person a = new Child();
the statement works as Child is a subclass of Person, so it's permitted in java, but I can't stop ...
0
votes
0
answers
81
views
subclass for NameError: name 'side_length' is not defined
class Polygon():
def __init__(self, side_lengths):
self.side_lengths = side_lengths
def perimeter(self):
return sum(self.side_lengths)
def __str__(self):
side_lengths = len(self....
1
vote
1
answer
41
views
Overridden method of sublcass from standard library can't find names in module
I was trying to a method in a sublcass of subprocess.Popen, namely its _execute_child method:
class MyPopen(Popen):
def _execute_child(self, args, executable, preexec_fn, close_fds,
...
-3
votes
2
answers
35
views
does anyone know much about python class? and its objects is giving me errors when i input some data
if unit == 'F': self.number = (number - 32) * 5/9
UnboundLocalError: local variable 'number' referenced before assignment
0
votes
1
answer
23
views
get the weights of a subclassed model
I have been playing around with movielens and collaborative filtering. I used a subclassed model and would like to get the trained embeddings to visualise them in 2d etc. Somehow the weights seem to ...
0
votes
1
answer
46
views
Childrens can't get the updated Parent values
I'm trying to create a Bank system using inheritance, the problem comes when the children BankAccount tries to retrive it's parent values, it gets the initial values of the Bank class, numberAccounts =...
0
votes
2
answers
55
views
How to cast an object of an ArrayList of objects (of type superclass) to an object of type subclass
If I have a superclass, let's call it Car, with the constructor parameters String name, String color, double wheelSize, and a subclass of this, let's call it Truck, with the constructor parameters ...
0
votes
0
answers
24
views
Need help passing variables from one sub classes to another in scala
So, I've created an abstract class and have multiple sub classes extending it. One of my sub classes holds all of my methods that I need as well as some global variables and from those variables one ...
0
votes
1
answer
94
views
Why does super closure not use the new base class given by a metaclass?
I'm toying with creating a class that dynamically has a base that is the class of an object passed to it on instantiation. E.g. pass it an int instance, and it subclasses int, etc. I'm trying to do ...
0
votes
0
answers
9
views
Undefined symbols for architecture x86_64 error for double linked list [duplicate]
Im trying to create a double linked list. With a link to Head and a link to the tail.
I wrote my Member functions in the liste.cpp (German for list and liste.hpp. There I also included the Node class
...
-2
votes
2
answers
53
views
Subclasses of an abstract class should have progressive ids starting at 0 for each class
I've spent an entire afternoon on this task that I really think is pretty easy to accomplish, but still I can't find where is my mistake.
Essentially what I have to do is having an abstract class ...
0
votes
0
answers
58
views
Unexpected behavior when subclass Tensorflow Keras Model with 3D input for dense layer
I am comparing two simple single dense layer regressors. The two regressors are only different in a way that the 2nd one I pass in index of data in the call function rather than real data and use ...
1
vote
1
answer
65
views
Create a final field initialized by a child class
I have an abstract class with subclasses that share a method that increments a value by a specific increment and is bounded by a lower limit and an upper limit. Each subclass has its own increment and ...