I am creating a game like system which contains a trainingSession window and a testSession window. In the trainingSession window i have created a method - public void stage() which contain the neccesary data to run the session. Now i want this exact same method used in the testSession window. But how can i call it? I do not want to copy and paste the entie method again.
Is there a way i can do this? Thanks, e.mack
or is it possible to have this method in its own cla开发者_运维问答ss file, which then can be called by both the trainingSession class and the testSession class... but then there would be alot of parameters needing to be passed over.
That's what inheritance is for!
Create a mustinherit class called baseSession. That's where method stage() goes.
Now, say that trainingSession and testSession both derive from baseSession. Voilà! -- stage() is now part of both testSession and trainingSession.
精彩评论