Questions tagged [superclass]

A superclass is a parent or base class that is derived or inherited from by a child class (or subclass). Superclasses are used extensively in object-oriented programming (OOP).

SuperClass

A superclass is a class that has been extended by another class. It allows the extending class to inherit its state and behaviors.

Example

In this example, polygon is a superclass of triangle and rectangle:

enter image description here

Reference

1474 questions
31
votes
5 answers

What's the closest thing in C++ to retroactively defining a superclass of a defined class?

Suppose I have the class class A { protected: int x,y; double z,w; public: void foo(); void bar(); void baz(); }; defined and used in my code and the code of others. Now, I want to write some library which could very well…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
30
votes
2 answers

Getting all superclasses in Python 3

How I can get a list with all superclasses of given class in Python? I know, there is a __subclasses__() method in inspent module for getting all subclasses, but I don't know any similar method for getting superclasses.
VeLKerr
  • 2,995
  • 3
  • 24
  • 47
30
votes
4 answers

Checking if A is superclass of B in Python

class p1(object): pass class p2(p1): pass So p2 is the subclass of p1. Is there a way to find out programmatically that p1 is [one of] the superclass[es] of p2 ?
Andz
  • 1,315
  • 1
  • 12
  • 14
29
votes
6 answers

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel specific here... …
Rene Saarsoo
  • 13,580
  • 8
  • 57
  • 85
28
votes
6 answers

Java. Implicit super constructor Employee() is undefined. Must explicitly invoke another constructor

Hello I'm new to Java, I'm getting this error in my production worker class. My Production worker constructor says explicitly invoke another constructor. I don't know what to do?. import java.util.Date; public class Employee { private String…
user659658
  • 285
  • 1
  • 4
  • 8
27
votes
4 answers

C# Call base class' constructor after own constructor?

How can I call base class' constructor after I've called my own constructor? The problem is, base class' constructor calls an abstract method (overridden in sub class), which needs to access variable x, initialized in sub class' constructor? Short…
user1632861
25
votes
9 answers

Use of Java [Interfaces / Abstract classes]

Lately i decided to take a look at Java so i am still pretty new to it and also to the approach of OO programming, so i wanted to get some things straight before learning more, (i guess it's never to soon to start with good practices). I am…
Samuel
  • 18,286
  • 18
  • 52
  • 88
22
votes
1 answer

How do you access properties of base class in Typescript?

There was a suggestion of using code like this class A { // Setting this to private will cause class B to have a compile error public x: string = 'a'; } class B extends A { constructor(){super();} method():string { return…
Alex Vaghin
  • 295
  • 1
  • 2
  • 6
21
votes
5 answers

ServiceConnectionLeaked in Android

I'm attempting to use a Service in Android for some basic database operations, but for some reason I'm getting an Activity has leaked ServiceConnection error. I'll post the full Logcat readout at the bottom. I have to use the same service in…
MrMannWood
  • 566
  • 1
  • 4
  • 15
21
votes
5 answers

PHP trait: is there a proper way to ensure that class using a trait extends a super class which contains certain method?

Example #2 from PHP manual http://php.net/manual/en/language.oop5.traits.php states
Maciej Sz
  • 11,151
  • 7
  • 40
  • 56
20
votes
1 answer

Kotlin: 'This type has a constructor and thus must be initialized here', but no constructor is declared

Recently started with Kotlin According to Kotlin docs, there can be one primary constructor and one or more secondary constructor. I don't understand why I see this error Since class test has no primary constructor. This works fine: open class test…
Shafayat Alam
  • 702
  • 1
  • 14
  • 32
19
votes
4 answers

Calling an overridden method, superclass an calls overridden method

This code throws an exception, AttributeError, "wtf!", because A.foo() is calling B.foo1(), shouldn't it call A.foo1()? How can I force it to call A.foo1() (and any method call inside A.foo() should call A.*) class A(object): def foo(self): …
19
votes
2 answers

IntelliJ IDEA: Is there a way to list all interfaces implemented by a class and its parents?

I work on a relatively complex Java project where classes commonly have four or five ancestors before Object. Given such a class, e.g. D in a hierarchy like this: Object > A > B > C > D, I would like to know what all interfaces it effectively…
mkorvas
  • 563
  • 3
  • 10
18
votes
9 answers

Is it possible to call subclasses' methods on a superclass object?

Animal is a superclass of Dog and Dog has a method called bark public void bark() { System.out.println("woof"); } Consider the following: Animal a = new Dog(); if (a instanceof Dog){ a.bark(); } What will happen? the assignment isn't…
roberto
18
votes
5 answers

Private members in Java inheritance

I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members. Can someone explain this to me. I am now totally confused.
Mandy M
  • 215
  • 1
  • 3
  • 5
1 2
3
98 99