We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I’m starting with Eclipse and also with the toxiclibs library. And I am a bit confused about how to work with “subclasses” that extends another class.
I’m trying to translate to Eclipse some examples of Shiffman’s book “Nature of Code”. For example “NOC_5_10_SimpleSpring.pde”. So I create a parent class (as the example sketch) that has a child-class “Particle” that “extends VerletParticle2D”.
I’m writing this subclass “Particle” like this:
import processing.core.PApplet;
import toxi.geom.Vec3D;
import toxi.physics.VerletParticle;
public class Particle extends VerletParticle {
PApplet p5;
Vec3D loc;
Particle( PApplet _p5, Vec3D _loc) {
p5 = _p5;
loc = _loc;
}
}
And I get this error:_ “Implicit super constructor VerletParticle() is undefined. Must explicitly invoke another constructor”_ and I don’t know exactly what this means.
In Toxiclibs library the class VerletParticle extends Vec3D, so is it possible that the new class “Particle” must have a constructor identically as a Vec3D constructor? Is it necessary? In this case, how to write in Eclipse a subclass that also extends another class?
Thank you for your help!
Answers
The Particle constructor must call super(...) where you replace the ... with the actual parameter names expected by VerletParticle.
The message just says that VerletParticle doesn't have a parameterless constructor, so you must call explicitly one of its defined constructors.
As an alternative, instead of extending VerletParticle, declare and instantiate it 1 inside your class.
Just like you did w/ PApplet & Vec3D instances. Check it out: *-:)
Shorter version extending VerletParticle: :D
@GoToLoop==
but in this type of case what is the interest of extending??? Could not be more simple && quick to write:
and add some display method with pos parameters???
@GoToLoop and @PhiLho, you help me so much!! Now I clearly see how I needed to call the "super(loc)". @GoToLoop: It´s very helpful to watch different alternatives and compare them. The best way to learn. @Akenaton: It is the way that Shiffman used to define classes (nodes, particles,...) in his book. Classes that extends VerletParticles with a display method costumized. thanks!!