Jump to content

Need help Working on High School game

So As my grade 12 final project i Have to do a game working with a partner.

 

I'm just have a basic question about how i should structure my code (our teacher wants it neat, and we wrote 3000 lines of code already and don't want to refactor it) : 

 

So, when when i call the constructor of a subclass, does it call the superclass constructor as well. and if it does it call the subclass first or the super class first?

 

if it matters, i am programming in java.

Link to comment
Share on other sites

Link to post
Share on other sites

In whatever computer science project, refactoring is a natural part of the business, so you will eventually benefit from doing it.

 

To answer your question: yes, the constructors of the superclasses are called if they receive the same arguments as the constructor that was called. If you do not have a constructor in your subclass that matches the arguments and types of any constructor in the superclass you get an error and you must use super(...) in the constructor you are in to call the constructor that receives  the same number and type of the arguments you specify in it (you can use super even if you have a constructor that matches to call that one instead). In whatever case, the supercalss constructor is called first.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×