superclass

Explicit passing of Self when calling super class's __init__ in python

烈酒焚心 提交于 2019-12-06 04:12:04
This question is in relation to posts at What does 'super' do in Python? , How do I initialize the base (super) class? , and Python: How do I make a subclass from a superclass? which describes two ways to initialize a SuperClass from within a SubClass as class SuperClass: def __init__(self): return def superMethod(self): return ## One version of Initiation class SubClass(SuperClass): def __init__(self): SuperClass.__init__(self) def subMethod(self): return or class SuperClass: def __init__(self): return def superMethod(self): return ## Another version of Initiation class SubClass(SuperClass):

python super calling child methods

流过昼夜 提交于 2019-12-06 03:46:00
问题 There are numerous questions on the usage of super() but none of them appears to answer my question. When calling super().__init__() from a subclass, all method calls in the super-constructor are actually taken from the subclass . Consider the following class structure: class A(object): def __init__(self): print("initializing A") self.a() def a(self): print("A.a()") class B(A): def __init__(self): super().__init__() # add stuff for B self.bnum=3 # required by B.a() def a(self): print("B.a(),

Java set super instance of instance

血红的双手。 提交于 2019-12-06 02:21:36
I might just be unable to google for the right words, but I can't find an answer to the following question. Is it possible to explicitly set the superclass of a new class instance. E.g. I have a SuperClazz instance and want to create a new instance of Clazz which extends SuperClazz . Can I just do something like this (the code is just what I want to do, it doesn't compile and is not correct): class Clazz extends SuperClazz{ Clazz(SuperClazz superInstance){ this.super = superInstance; } } The super class is always instantiated implicitly, so you cannot do it — "plant" the super class inside an

Java: Can a class inherit from two super classes at the same time?

孤人 提交于 2019-12-06 00:04:01
I have a class Journey which I want to make a superclass and another class plannedjourney. The plannedjourney class extends JFrame since it contains forms..However I also want this class to extends Journey.. Is there a possible way to do this? Don't mix models and views. If you keep both domains clearly separated, then you won't be in need of multiple inheritance (this time). You have one model class for journeys and a viewer for such journeys. The viewer should subclass Component and be displayed (somewhere) in your window (a JFrame instance). This viewer takes one journey object and presents

extending superclass and ClassCastException

喜欢而已 提交于 2019-12-05 12:25:28
I have a superclass, which two methods i want to override. Here's my code: public class MyCustomClass extends SomeSuperClass { protected MyCustomClass(params) { super(params); } @Override public void method1() { super.method1(); /* here goes my code */ } @Override public void method2() { super.method2(); /* here goes my another code */ } I have some constructor, that passes SomeSuperClass object as a parameter, and what i do next: MyCustomClass object; /* now i have object of type SomeSuperClass, but with my own method1() and method2() */ object = (MyCustomClass) MyCustomClass.item(blahblah);

Javascript Prototype Chaining super class constructor and method calling

余生长醉 提交于 2019-12-05 08:04:29
I'm a newbie in the JavaScript world, and I came up with this weird problem when i was attempting prototype chaining inheritence. I have 3 classes //class parent function parent(param_1){ this.param = param_1; this.getObjWithParam = function(val){ console.log("value in parent class "+val); console.log("Constructor parameter : "+this.param); }; }; //class child function child(param_1){ this.constructor(param_1); this.getObjWithParam = function(val){ console.log("value in child class "+val); val = Number(val)+1; child.prototype.getObjWithParam.call(this, [val]); }; }; child.prototype = new

Strange error regarding instance variables & superclass

∥☆過路亽.° 提交于 2019-12-05 04:57:12
I've got some code where my classes inherit from a superclass, and everything has been working fine till now. I'm getting an error whenever I try to use any of the superclass variables, saying that they are undeclared (first use in this function). It's only happening in one of my subclasses, & it looks exactly the same as the others. I'm wondering if there's anything obvious which I should know about (being quite new to Objective-C). The basic code is like - @interface mySuperClass : UIViewController { BOOL myVar; } Then - @interface mySubClass : mySuperClass { } @implementation mySubClass { -

python3 - behaviour of super() on multi-inheritance

给你一囗甜甜゛ 提交于 2019-12-05 02:53:56
I know that super() and multi-inheritance have already been discussed here. But I did not find a solution, regarding my specific problem in python3. Let's assume we have: #! /usr/bin/env python3 class A(object): def __init__(self): super().__init__() def foo(self): print("The") class B(object): def __init__(self): super().__init__() def foo(self): print("world") class C(B): def __init__(self): super().__init__() def foo(self): super().foo() print("is") class D(A,C): def __init__(self): super().__init__() def foo(self): super().foo() print("nice") d = D() d.foo() This will get me: The nice On

Do I need to call [super init] or [super initWithCoder], etc for NSObject

这一生的挚爱 提交于 2019-12-05 01:25:56
Typically when I subclass from a UI class I will call the superclass initializer of interest. However, I'm not sure of the implementation details of NSObject , and it seems like there's not much going on in terms of member vars, so I wonder: do I need to call [super init] if my subclass extends NSObject ? John Calsbeek Technically, no. The documentation for -[NSObject init] says that The init method defined in the NSObject class does no initialization; it simply returns self . Because it is documented and there's probably already a bunch of code that relies on it, that fact is highly unlikely

How do you call a method for an Objective-C object's superclass from elsewhere?

ⅰ亾dé卋堺 提交于 2019-12-04 22:52:50
If you're implementing a subclass, you can, within your implementation, explicitly call the superclass's method, even if you've overridden that method, i.e.: [self overriddenMethod]; //calls the subclass's method [super overriddenMethod]; //calls the superclass's method What if you want to call the superclass's method from somewhere outside the subclass's implementation, i.e.: [[object super] overriddenMethod]; //crashes Is this even possible? And by extension, is it possible to go up more than one level within the implementation, i.e.: [[super super] overriddenMethod]; //will this work? A