superclass

Calling an overridden method, superclass an calls overridden method

风格不统一 提交于 2019-12-01 02:37:12
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): print self.foo1() def foo1(self): return "foo" class B(A): def foo1(self): raise AttributeError, "wtf!" def foo(self): raise AttributeError, "wtf!" def foo2(self): super(B, self).foo() myB = B() myB.foo2() In class A instead of calling self methods you need to call A methods and pass in self manually. This is not the normal way of doing things -- you

implicit super constructor Person() is undefined. Must explicitly invoke another constructor?

こ雲淡風輕ζ 提交于 2019-12-01 02:19:22
I am working on a project and i am getting the error "implicit super constructor Person() is undefined. Must explicitly invoke another constructor" and i don't quite understand it. Here is my person class: public class Person { public Person(String name, double DOB){ } } And my student class when trying to implement the person class, and giving it an instructor variable. public class Student extends Person { public Student(String Instructor) { } } If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor

Calling an overridden method, superclass an calls overridden method

99封情书 提交于 2019-11-30 22:12:42
问题 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): print self.foo1() def foo1(self): return "foo" class B(A): def foo1(self): raise AttributeError, "wtf!" def foo(self): raise AttributeError, "wtf!" def foo2(self): super(B, self).foo() myB = B() myB.foo2() 回答1: In class A instead of calling self

implicit super constructor Person() is undefined. Must explicitly invoke another constructor?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 16:27:44
问题 I am working on a project and i am getting the error "implicit super constructor Person() is undefined. Must explicitly invoke another constructor" and i don't quite understand it. Here is my person class: public class Person { public Person(String name, double DOB){ } } And my student class when trying to implement the person class, and giving it an instructor variable. public class Student extends Person { public Student(String Instructor) { } } 回答1: If a constructor does not explicitly

Java Web Services/JAXB - Abstract superclass

眉间皱痕 提交于 2019-11-30 07:02:19
I have a package with JAXB annotated classes with an abstract superclass. I want to use this superclass in web service interface, so I can pass any of subclasses as a parameter. When I do it, an exception is thrown: javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.bind.UnmarshalException: Unable to create an instance of xxx.yyy.ZZZ - with linked exception: [java.lang.InstantiationException]] It is possible to manually marshall/unmarshall & pass parameter as a string, but I would like to avoid it. Any ideas how to do it? Have you specified

How to determine if an object is an instance of certain derived C++ class from a pointer to a base class in GDB?

旧街凉风 提交于 2019-11-30 06:17:44
问题 I'm debugging a C++ program with GDB. I have a pointer to an object of certain class. The pointer is declared to be of some super class which is extended by several sub-classes. There is no fields in the object to specify the precise class type of this object but some virtual functions (e.g. bool is_xxx()) are defined to tell the class type at runtime. Is there some way to tell the precise class type of an object in GDB without calling these virtual functions. Calling such functions in GDB

Better way to call superclass method in ExtJS

感情迁移 提交于 2019-11-29 22:57:47
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... MyApp.MyPanel.superclass.initComponent.call(this); } }); I have been using this pattern for quite some time and the main problem is, that when you rename your class then you also have to change all the calls to superclass methods. That's quite inconvenient, often I will forget and then I have to track down strange errors. But reading the source of Ext.extend() I discovered, that instead I

Java: returning subclass in superclass method signature

纵然是瞬间 提交于 2019-11-29 16:12:35
问题 I'm working on a problem where there are several implementations of Foo , accompanied by several FooBuilder 's. While Foo 's share several common variables that need to be set, they also have distinct variables that require their respective FooBuilder to implement some specific functionality. For succinctness, I'd like to have the FooBuilder 's setters to use method chaining, like: public abstract class FooBuilder { ... public FooBuilder setA(int A) { this.A = A; return this; } ... } and

Why does it store or allocate memory for super class variables, in sub class object?

前提是你 提交于 2019-11-29 13:05:14
In the following code- class Mammal { String name = "furry "; String makeNoise() { return "generic noise"; } } class Zebra extends Mammal { String name = "stripes "; String makeNoise() { return "bray"; } } public class ZooKeeper { public static void main(String[] args) { new ZooKeeper().go(); } void go() { Mammal m = new Zebra(); System.out.println(m.name + m.makeNoise()); Zebra z = new Zebra(); System.out.println(z.name + z.makeNoise()); } } Both objects ( m and z ), if I see in debug windows of eclipse, contain both values of name variable ( furry and stripes ). I do understand that in

Java — Initializing superclass variables in subclasses?

六月ゝ 毕业季﹏ 提交于 2019-11-29 10:32:37
Okay, so, for example, let's say I have an abstract class called "Vehicle". The Vehicle class, has, among other things, a static variable called wheels, which is not initialized. What I want to do is have other subclasses extending from the Vehicle class, like "Motorcycle", and "Truck", and in these subclasses, have the wheels initialized. Code: public abstract class Vehicle { static int wheels; //number of wheels on the vehicle } But the below doesn't work: public class Motorcycle extends Vehicle { wheels = 2; } Is there a way to do this effectively? EDIT: Thank you to all the people who