All Questions
Tagged with inheritance oop
4,842
questions
4
votes
1
answer
94
views
Assign base object without changing inherited ones?
How valid is it to assign a new object to a base one, without changing the inherited ones?
The example below works as expected, but is it by chance?
This example is simple, but is there any situation ...
-2
votes
1
answer
54
views
When calling an inherited method from a derived class it tries to use the uninitialised fields of the base class [closed]
I have two classes. One called Agent, and the other called Player. Agent is the base class and Player is the derived class.
When calling the function SetHand() from the derived Player class, I run ...
3
votes
1
answer
68
views
Why objects having instance of a class with private property in prototype throw when accessing private member?
Consider this code:
class Klass {
#priv = 42
get pub() {
return this.#priv
}
}
// these two correctly return 42
console.log(new Klass().pub);
console.log((new class extends Klass {})....
1
vote
3
answers
81
views
Inheriting Structs in C++
I am working with the LibAV library, converting it from C to C++ (and moving to an object oriented style).
This library has structs to hold data, which need to be created using specific allocation ...
0
votes
1
answer
65
views
Calling student method from parent class definition
I'm making an LCD menu and having trouble with the lcdmenu (main menu) and submenu interaction.
class submenu;
class lcdmenu
{
protected:
command **commandlist;
submenu **submenulist;
... ...
0
votes
1
answer
76
views
Abstract function's copy constructor deleted, class inherited from this class gives error
Given header files named Point.h:
#pragma once
struct Point {
double x, y;
};
and Shape.h:
#pragma once
#include "Point.h"
#include <vector>
class Shape {
public:
...
1
vote
1
answer
49
views
Constructor parameter is null until parent is not initialized
Look at the following code:
abstract class A {
init {
f()
}
abstract fun f()
}
class B(val p: () -> Unit) : A() {
override fun f() {
try {
p()
...
0
votes
2
answers
60
views
Initializing properties of derived classes in Kotlin
I want to know why exactly my code returns "nullnullnull" instead of expected answer and why does it work correctly when method is used.
Consider the following code:
open class Base(
...
0
votes
0
answers
20
views
Bug with diamon-shaped inheritance in Python [duplicate]
I am trying to use inheritance in which I have a base class, say X, and 2 classes which both independently inherit from X, say A(X) and B(x) (these represent the common attributes of a whole bunch of ...
0
votes
1
answer
26
views
can't reassign a class variable when inheriting in TypeScript
I am created a lexer parser etc etc. I created a custom call called Error, and a LexerErr class inehriting from the Error class.
The Error class accepts many variables in its constructor, one of the ...
0
votes
0
answers
17
views
Superclass Function [duplicate]
How does the flow of inheritance work?
class A:
def method1(self):
print("one")
class B(A):
def method1(self):
print("two")
super().method1()
...
2
votes
2
answers
37
views
Composition over Inheritance - code duplication
I would appreciate some clarification on how to properly implement 'Composition over Inheritance'. I think I have a grasp on the theory but in practice I struggle to understand how it doesn't lead to ...
0
votes
1
answer
37
views
Creating instance of child class in parent method
I have something similar to the following code for a parent and child class:
const modify = (data) => {
const newData = data
// changes newData in some way
return newData
}
class Parent {
...
0
votes
1
answer
53
views
Python with CustomTkinter - Splitting app across multiple python files
I currently have a small app using CustomTkinter. The whole app is an instance of Class App. The Class has some methods to draw the sections of UI, and methods that do background tasks that can update ...
-2
votes
1
answer
27
views
Is there a way to access a variable from a acctual CHILD class?
ps: I dont want to acess a parent class var but rather an actual child class
How do I access the $table var from User class? I know it sounds silly but is there a way to access this child class var ...