Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4095496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:54:20+00:00 2026-05-20T19:54:20+00:00

I am new to OOP, and I’m trying to make a simple game to

  • 0

I am new to OOP, and I’m trying to make a simple game to help me learn Java. My idea was to make an enemy class, but I want the amount of enemies to be dynamic. I tried making a new object as an array rather than manually typing attker1 attker2 and so on …

Mole attacker[3];
attacker[0] = new Mole();
attacker[1] = new Mole();
attacker[2] = new Mole();

I hope you get the idea of what I’m trying to do. I’ve tried searching Google, but I keep getting tutorials on how to make arrays out of regular data types (i.e. int, char, etc.). I’d like to know what it’s called, whatever I’m trying to do. If there is a better way of doing this I’ll listen to that too.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:54:21+00:00Added an answer on May 20, 2026 at 7:54 pm

    Arrays of objects are perfectly fine (indeed, often used more than simple arrays of primitive data types).

    So, if you want the amount of enemies to be dynamic, you might want to use a Container class- specifically a resizable array. Look into classes Vector, ArrayList, etc.

    Also note (I saw the Android tag) that creating new objects in the drawing loop can cause the Garbage Collector to be called and slow down the framerate while it works – be warned.

    A variation on what you have:

    //create enemies
    Mole enemies[3];
    enemies[0] = new Mole();
    enemies[1] = new Mole();
    enemies[2] = new Mole();
    
    //an enemy dies!
    enemies[1] = null;
    
    //and comes back to life!
    enemies[1] = new Mole();
    
    //do something with your enemies....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to OOP, eager to learn good habits. I want to make a vectorMap
I'm new to PHP oop stuff. I'm trying to create class database and call
I'm new to OOP and could use some help. My class is not working:
I am new to OOP and I am trying to rewrite a simple JS
I'm new to OOP. I created this class called Site that is extended but
I am fairly new to OOP but not new to PHP. I am trying
I'm really new to OOP and C# and I'm trying to understand, how I
I am fairly new to OOP and wondered if you could provide some help
I'm new to the OOP paradigm, so there's probably a simple explanation for this
I'm new to OOP in PHP, is that to seems correct ? class whatever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.