Question:

How do you create multiple Java classes in one file?

by Guest21250  |  earlier

0 LIKES UnLike

I want to make a program thats like an RPG. I have a ninja class file that has methods such as attack, explore, rest, etc... Then I have the tester class file and all the methods work as i wanted them to. But now, i want to create another class, such as an Enemy class. How do i have the two classes (ninja and enemy) interact? Any help is appreciated. Thank you!

 Tags:

   Report

3 ANSWERS


  1. The methods of one case can invoke public methods of the other as long as the invoked class is defined before the invoking class (or the methods are prototyped first.) If the classes are in different files, have the invoker file include the invoked.


  2. Have the main class, the class that is the "application", with the main() method, instantiate ninja objects and enemy objects, and then invoke their various methods.

  3. Java Coding-http://codingjava.blogspot.com/

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.