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

Insight.Database [BindChildren] on subclass not working

I am using insight.database with my c# project. I Have a class that has a subclass. I am using an inner join in my SP to flatten and get my fields. However, I want some of the query result fields to map to my subclass. It's not working as I…
KidFischer
  • 11
  • 3
1
vote
1 answer

Change instance type to inheritance in python

I have a class Person and 2 classes Child and Adult that inherit from `Person. class Person: def __init__(self, name): self.name = name self.age = 0 def say_hi(self): print("Hi, I am " + self.name) def…
Ivan
  • 1,352
  • 2
  • 13
  • 31
1
vote
1 answer

Inherited print on screen in subclasses: ostream flow from the parent class

My apologies for the bad title, I'm self-taught c++ newbie. I'd coding the usual example of a Company class along with Employess class and Person class. Basically my code should create a company, add employees to that and print the full list of…
1
vote
2 answers

How statement 3 is false and 4 true

class Vehical{} public class Car extends Vehical { public static void main(String[] args) { Vehical v = new Vehical(); Car c = new Car(); boolean is = v instanceof Vehical; System.out.println("is v instanceof…
1
vote
2 answers

How does inheritance work in this bit of code?

So guys I've been playing around with inheritance and I've stumbled upon this program : public class HelloWorld { static class A { void f() { System.out.println("A"); } } static class B extends A { void f() {…
zxzx28
  • 15
  • 4
1
vote
2 answers

Subclassing LINQ to SQL Data Entities - Bad Idea or Missing Something?

I would like to be able to subclass automatically generated LINQ to SQL Data Classes and save changes to said objects. For example, if I have a table Client in my database, I can create ClientBO that extends class Client, and adds behaviors like…
Bob Kaufman
  • 12,864
  • 16
  • 78
  • 107
1
vote
1 answer

C++ How to make an unordered_map with subclasses

I'm making a game engine and currently I'm working on Entity Component System. Here is some code for better understanding: class Entity { public: ... void AddComponent(EntityComponent component, unsigned int id){ …
1
vote
1 answer

Subclassing Formatter crashes on initializer

I am trying to subclass the Formatter class to perform validation on text fields. The application is crashing when super.init() is called: class LengthFormatter: Formatter { private var maxLength: Int init(_ maxLength: Int) { self.maxLength =…
evilmandarine
  • 4,241
  • 4
  • 17
  • 40
1
vote
0 answers

What is the purpose of self.__class__, __name__, and __repr__ in this example?

I'm new to python (and coding in general) and I've been really struggling to wrap my head around classes. I feel like the concept of a class is just starting to click for me, but adding sub-classes (is that the same thing as a meta-class???) into…
1
vote
2 answers

Creating multiple instances of a subclass, with only one instance of a superclass

I'm trying to implement the Flyweight pattern, but I'm not quite sure how inheritance works, and so I'm not quite sure how this pattern works. Let's say I have a superclass that holds all the "heavy" information - textures, etc., the instrinsic…
user12468788
1
vote
1 answer

What is the correct subclass to link storyboard and swiftUI?

I have created the subclass below to link my swiftui code to my storyboard. The goal is to have a vstack with text containers in it display inside a ContainerView. I am not sure if I am using the right class: NSViewController? I do not get any…
Stratocasder
  • 107
  • 1
  • 1
  • 8
1
vote
2 answers

I am not able to get input after a certain point ( from the user) even though no error pops wile compiling

This program is a small hospital management program. It works with C++ and uses binary files and classes. it is a simple prog that taken the input of patients details and saves in a binary file, and displays the patients details by searching…
1
vote
6 answers

Class design question [optional implementation]

I was wondering how to design a system in which I have a class Super and a couple of classes that are subclasses of Super (let's say Sub1, Sub2, Sub3) and I want a class Cool. Now there are two things I want to have: Sub1 and Sub2 can be Cool's,…
Samuel
  • 18,286
  • 18
  • 52
  • 88
1
vote
2 answers

Best way to represent structure where subclass is like a superclass with one object

I want to represent a structure that is something like an unordered deck of cards (in Python 3.7, say), which has the property that a single card can be thought of as a deck of size one. class Deck: def __init__(self, cards, owner): …
1
vote
1 answer

Overload constructors of subclass

So i have an abstract class: public abstract class Superclass { private final boolean isTrue; private final int number1; private final int number2; private final int number3; public Superclass(boolean isTrue, int number1, int…
vader69
  • 27
  • 3