简体   繁体   中英

How to declare subclass constructor in java

I have an abstract class, Entity.java. I also have a class TransportUnit.java that extends the Entity class. Entities are to be constructed with a String name and int lifePoints. Transport Units are to be constructed with the same and in addition an empty Set. My question is how to write the constructor for the TransportUnit class and why? Thanks in advance.

You would write it more or less the same way as a normal constructor, just calling super() Set s;

public TransportUnit(String name, int lifePoints){
  super(name, lifePoints);
  s = new HashSet(); //or other type of set

}

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