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 8300643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:38:15+00:00 2026-06-08T16:38:15+00:00

How do I create an array of different types? If each class is an

  • 0

How do I create an array of different types? If each class is an extension of the _object class, can I just make an _object array and add the extensions to it?

Example:

class _object {
    int type = 1;
    public _object() {
        type = 2;
    }

    public doSomething() {
    }
}

class tree extends _object {
    public tree() {
    }
}

class apple extends _object {
    public apple() {
    }
}

public tree aTree = new tree();
public apple anApple = new apple();

public _object[] objects = new _object[] { aTree, anApple };
  • 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-06-08T16:38:16+00:00Added an answer on June 8, 2026 at 4:38 pm

    The example in your question works. This is known as polymorphism.

    http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html

    http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can c++ create array of pointers to different classes dynamically loaded from dll? ps.without
I want to create a 2D array which can be used for two different
I need an advice about how to create new string array from 4 different
I'm new to programming and I'm trying to create an array of class objects,
Arrays can be indexed using user-defined enumerated types. For example: type TIndexValue = (ZERO
I create array: TextBox[] textarray = new TextBox[100]; Then in cycle set this params,
How to create array of generic type? How does generic Arrays.copyOf() method work? It
I create an array that then prints in sets of five. I want to
I need to create an array for time that I will use in a
I need to create an array of label and text boxes dynamically. I have

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.