[Solved]Is it not possible to give a subclass a function that a superclass can call with the correct variables?
in
Programming Questions
•
8 months ago
I come from a C++/AS3 background and I just picked up processing to see what its capable of. Unfortunatly I keep running into a brick wall with this issue. What is the best way to overwrite subclass variables?
- class Atom{
- String icon="";
- Atom(float _x,float _y){
- x=_x;
- y=_y;
- atoms.add(this);
- if(!icon.equals("")){
- println(icon); //Will be blank
- PImage img=loadImage(icon);
- image(img,x,y);
- bounds[2]=img.width;
- bounds[3]=img.height;
- }
- }
- class Mob extends Atom{
- String icon="guy.png"; //The problem is if the variable is initialized like this in Atom() it will read icon as ""
- Mob(float _x,float _y){
- super(_x,_y);
- println(icon); //WIll be "guy.png"
- }
- }
- void setup(){
- size(600,600);
- new Mob(50,50);
- noLoop();
- }
- void draw(){
- }
Is there a better approach or is this language fatally flawed?
1