Skip to main content

All Questions

Tagged with
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 ...
T.L's user avatar
  • 684
0 votes
1 answer
79 views

Why is there no error if a class defines a member with the same name and type as the class it inherits? Which of the two members is used? [duplicate]

I am currently learning programming in university and I was messing around and wrote this code and I got curious: class Student{ public: string name; string address; }; class Instructor: ...
Zoran I's user avatar
  • 11
0 votes
1 answer
78 views

Request for member which is of non-class type void*

I am trying to do a pointer to generic object type of thing but i don't get how to access the arbitrary object method. I tried definining an interface class InterfaceProtocol{ public: virtual ...
Hans Carrizales's user avatar
2 votes
1 answer
91 views

Should name mangling be used in classes that are inherited by other subclasses?

I'm trying to create classes and subclasses in python with "protected" attributes using name mangling (__). However, when I try to extend the functionality of classes further with different ...
Joshua Mincer's user avatar
0 votes
1 answer
146 views

Dealing with the Diamond Problem in Python

I'm working on a project where I need to implement multiple inheritance in Python, and I'm concerned about encountering the "diamond problem." I want to make sure I handle it properly to ...
DAKSHIN M's user avatar
0 votes
0 answers
67 views

Dealing with the Diamond Problem in Python: Implementing Multiple Inheritance Safely

I'm working on a project where I need to implement multiple inheritance in Python, and I'm concerned about encountering the "diamond problem." I want to make sure I handle it properly to ...
DAKSHIN M's user avatar
0 votes
1 answer
36 views

Declaring and initializing object of type child class in its base class

What's the name of the code smell committed by the following code. I try to google around to find the de-facto name of the following code smell to no avail. The reason why I'm searching for it is ...
caramel1995's user avatar
  • 2,985
0 votes
1 answer
34 views

How Inheritance is used to set values?

In below code , Level class have a construtor where it uses super. When happens when object is created with the value ? I'm literally confused, even can't explain what's my doubt please explain the ...
 VASANTH N's user avatar
0 votes
1 answer
82 views

Class inheritance issue: Unsupported operand types for * 'float', and 'class'

I am new to python, and exploring the class inheritance feature. In my code attached here, I have two classes, by the names "Waveguide" and "taper". The attributes for the ...
rakeshk's user avatar
0 votes
1 answer
43 views

Why is the compiler not throwing error when Assigning object of sub class to parent reference

class Base { public void show() { System.out.println("Base class show() method called"); } } class Derived extends Base { public void show() { System.out.println(...
Goutham's user avatar
  • 39
1 vote
1 answer
98 views

Creating child classes that only inherit parents data once

Currently I'm trying to create some attribute let's call it "DoNotShareWithGrandChildren" that will be used by the highest level parent class but not the children classes below it. The issue ...
Caleb Laws's user avatar
0 votes
1 answer
78 views

Difference between "SuperInterface of an Interface" vs "Direct SuperInterface of an Interface" in Java?

How can an Interface override a method of Object class? Why 'Collection' Interface Overrides equals(Object o) method and hashCode() method of Object class? https://docs.oracle.com/en/java/javase/11/...
Anand Pandey's user avatar
1 vote
2 answers
307 views

How to enforce constructor signature across sub-classes?

I want to dynamically instantiate sub-classes of a given class, and I need a consistent signature for the sub-classes' constructors to avoid errors at runtime. Constructors can be defined with ...
Cutter's user avatar
  • 1,786
2 votes
1 answer
271 views

dataclass __annotation__ not working with inheritance

I tried this code: from dataclasses import dataclass @dataclass class Data1: d11: str d12: float @dataclass class Data2: d21: str d22: float @dataclass class D3(Data1, Data2): pass ...
Alex's user avatar
  • 636
1 vote
0 answers
499 views

Derived class is not able access Base class variable [duplicate]

#include<iostream> #include<cstdio> #include<vector> #define MAX_SIZE 100 using namespace std; template<class T> class Base{ public: int top = 0; }; template<class T&...
J Jeshwanth Reddy's user avatar

15 30 50 per page
1
2 3 4 5
48