简体   繁体   中英

How do I extend a class?

I have a class: Model , with many functions, such as draw() , rotate() etc.

now i have another class called Cube that i want to be able to work the same way as Model.

I have this in my Cube class constructor:

Model m3d = new Model();        
m3d.build(obj);

So what i want is to be able to in another class call something like:

mCube.draw();

and m3d will perform draw() .

Ok. So do this in the class call:

class Cube extends Model {...}

Then you can do:

Cube mCube = new Cube();        
mCube.build(obj);
mCube.draw();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM