Difference between Object[] and Array of specific Objects in java












-6















I know this may be trivial but I could not find an answer yet.



What are the differences between and Object and an array of specific Objects, for example



class car {
public Object someCars;
public car someOthercars;
}


I know that car can store car Objects and Object can store any Objects. But APART from this are there any not so obvious differences?










share|improve this question




















  • 2





    What is the difference between an Object and Car variable ?

    – AxelH
    Jan 2 at 14:01













  • Object can contain any Objects. car can contain instances of car. As you might expect.

    – khelwood
    Jan 2 at 14:02













  • Open a book before you ask.

    – Bouramas
    Jan 2 at 14:03











  • @khelwood. So the only difference is that Object can contain any objects while car can only store car objects?

    – CuriousIndeed
    Jan 2 at 14:05






  • 1





    Possible duplicate of What's Object Oriented Programming?

    – Anton Hlinisty
    Jan 2 at 14:07
















-6















I know this may be trivial but I could not find an answer yet.



What are the differences between and Object and an array of specific Objects, for example



class car {
public Object someCars;
public car someOthercars;
}


I know that car can store car Objects and Object can store any Objects. But APART from this are there any not so obvious differences?










share|improve this question




















  • 2





    What is the difference between an Object and Car variable ?

    – AxelH
    Jan 2 at 14:01













  • Object can contain any Objects. car can contain instances of car. As you might expect.

    – khelwood
    Jan 2 at 14:02













  • Open a book before you ask.

    – Bouramas
    Jan 2 at 14:03











  • @khelwood. So the only difference is that Object can contain any objects while car can only store car objects?

    – CuriousIndeed
    Jan 2 at 14:05






  • 1





    Possible duplicate of What's Object Oriented Programming?

    – Anton Hlinisty
    Jan 2 at 14:07














-6












-6








-6








I know this may be trivial but I could not find an answer yet.



What are the differences between and Object and an array of specific Objects, for example



class car {
public Object someCars;
public car someOthercars;
}


I know that car can store car Objects and Object can store any Objects. But APART from this are there any not so obvious differences?










share|improve this question
















I know this may be trivial but I could not find an answer yet.



What are the differences between and Object and an array of specific Objects, for example



class car {
public Object someCars;
public car someOthercars;
}


I know that car can store car Objects and Object can store any Objects. But APART from this are there any not so obvious differences?







java arrays object






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 14:22







CuriousIndeed

















asked Jan 2 at 14:00









CuriousIndeedCuriousIndeed

986




986








  • 2





    What is the difference between an Object and Car variable ?

    – AxelH
    Jan 2 at 14:01













  • Object can contain any Objects. car can contain instances of car. As you might expect.

    – khelwood
    Jan 2 at 14:02













  • Open a book before you ask.

    – Bouramas
    Jan 2 at 14:03











  • @khelwood. So the only difference is that Object can contain any objects while car can only store car objects?

    – CuriousIndeed
    Jan 2 at 14:05






  • 1





    Possible duplicate of What's Object Oriented Programming?

    – Anton Hlinisty
    Jan 2 at 14:07














  • 2





    What is the difference between an Object and Car variable ?

    – AxelH
    Jan 2 at 14:01













  • Object can contain any Objects. car can contain instances of car. As you might expect.

    – khelwood
    Jan 2 at 14:02













  • Open a book before you ask.

    – Bouramas
    Jan 2 at 14:03











  • @khelwood. So the only difference is that Object can contain any objects while car can only store car objects?

    – CuriousIndeed
    Jan 2 at 14:05






  • 1





    Possible duplicate of What's Object Oriented Programming?

    – Anton Hlinisty
    Jan 2 at 14:07








2




2





What is the difference between an Object and Car variable ?

– AxelH
Jan 2 at 14:01







What is the difference between an Object and Car variable ?

– AxelH
Jan 2 at 14:01















Object can contain any Objects. car can contain instances of car. As you might expect.

– khelwood
Jan 2 at 14:02







Object can contain any Objects. car can contain instances of car. As you might expect.

– khelwood
Jan 2 at 14:02















Open a book before you ask.

– Bouramas
Jan 2 at 14:03





Open a book before you ask.

– Bouramas
Jan 2 at 14:03













@khelwood. So the only difference is that Object can contain any objects while car can only store car objects?

– CuriousIndeed
Jan 2 at 14:05





@khelwood. So the only difference is that Object can contain any objects while car can only store car objects?

– CuriousIndeed
Jan 2 at 14:05




1




1





Possible duplicate of What's Object Oriented Programming?

– Anton Hlinisty
Jan 2 at 14:07





Possible duplicate of What's Object Oriented Programming?

– Anton Hlinisty
Jan 2 at 14:07












2 Answers
2






active

oldest

votes


















4














Car can contain only Car instances, or sub-classes of Car instances.
If you were to have a class like this: class Honda extends Car , Honda instances can be populated in the Car array as well, because Honda extends from Car.



Object can contain any Object instances, or any subclass of Object (every class in Java is a subclass Object, even if it is not explicitly stated with an extends keyword in a custom class), so any instance in java can be populated in the Object array.






share|improve this answer

































    1














    Answers to your questions are given here:





    1. The Java™ Tutorials. Classes

    2. The Java™ Tutorials. Object-Oriented Programming Concepts


    UPD



    Car class inherits from Object. An array of Cars is narrower than an array of Objects. So roughly speaking if you store your cars in an array of objects - you will need to cast them back to cars each time you want to use an instance. I doubt that you really need that.






    share|improve this answer


























    • Don't see any reference to Object Arrays within your link

      – CuriousIndeed
      Jan 2 at 14:14






    • 1





      @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

      – Anton Hlinisty
      Jan 2 at 14:22






    • 2





      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

      – BoarGules
      Jan 2 at 14:28











    • @BoarGules added textual explanation

      – Anton Hlinisty
      Jan 2 at 14:36











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007675%2fdifference-between-object-and-array-of-specific-objects-in-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    Car can contain only Car instances, or sub-classes of Car instances.
    If you were to have a class like this: class Honda extends Car , Honda instances can be populated in the Car array as well, because Honda extends from Car.



    Object can contain any Object instances, or any subclass of Object (every class in Java is a subclass Object, even if it is not explicitly stated with an extends keyword in a custom class), so any instance in java can be populated in the Object array.






    share|improve this answer






























      4














      Car can contain only Car instances, or sub-classes of Car instances.
      If you were to have a class like this: class Honda extends Car , Honda instances can be populated in the Car array as well, because Honda extends from Car.



      Object can contain any Object instances, or any subclass of Object (every class in Java is a subclass Object, even if it is not explicitly stated with an extends keyword in a custom class), so any instance in java can be populated in the Object array.






      share|improve this answer




























        4












        4








        4







        Car can contain only Car instances, or sub-classes of Car instances.
        If you were to have a class like this: class Honda extends Car , Honda instances can be populated in the Car array as well, because Honda extends from Car.



        Object can contain any Object instances, or any subclass of Object (every class in Java is a subclass Object, even if it is not explicitly stated with an extends keyword in a custom class), so any instance in java can be populated in the Object array.






        share|improve this answer















        Car can contain only Car instances, or sub-classes of Car instances.
        If you were to have a class like this: class Honda extends Car , Honda instances can be populated in the Car array as well, because Honda extends from Car.



        Object can contain any Object instances, or any subclass of Object (every class in Java is a subclass Object, even if it is not explicitly stated with an extends keyword in a custom class), so any instance in java can be populated in the Object array.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 2 at 14:26

























        answered Jan 2 at 14:09









        Daniel B.Daniel B.

        1,2991112




        1,2991112

























            1














            Answers to your questions are given here:





            1. The Java™ Tutorials. Classes

            2. The Java™ Tutorials. Object-Oriented Programming Concepts


            UPD



            Car class inherits from Object. An array of Cars is narrower than an array of Objects. So roughly speaking if you store your cars in an array of objects - you will need to cast them back to cars each time you want to use an instance. I doubt that you really need that.






            share|improve this answer


























            • Don't see any reference to Object Arrays within your link

              – CuriousIndeed
              Jan 2 at 14:14






            • 1





              @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

              – Anton Hlinisty
              Jan 2 at 14:22






            • 2





              While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

              – BoarGules
              Jan 2 at 14:28











            • @BoarGules added textual explanation

              – Anton Hlinisty
              Jan 2 at 14:36
















            1














            Answers to your questions are given here:





            1. The Java™ Tutorials. Classes

            2. The Java™ Tutorials. Object-Oriented Programming Concepts


            UPD



            Car class inherits from Object. An array of Cars is narrower than an array of Objects. So roughly speaking if you store your cars in an array of objects - you will need to cast them back to cars each time you want to use an instance. I doubt that you really need that.






            share|improve this answer


























            • Don't see any reference to Object Arrays within your link

              – CuriousIndeed
              Jan 2 at 14:14






            • 1





              @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

              – Anton Hlinisty
              Jan 2 at 14:22






            • 2





              While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

              – BoarGules
              Jan 2 at 14:28











            • @BoarGules added textual explanation

              – Anton Hlinisty
              Jan 2 at 14:36














            1












            1








            1







            Answers to your questions are given here:





            1. The Java™ Tutorials. Classes

            2. The Java™ Tutorials. Object-Oriented Programming Concepts


            UPD



            Car class inherits from Object. An array of Cars is narrower than an array of Objects. So roughly speaking if you store your cars in an array of objects - you will need to cast them back to cars each time you want to use an instance. I doubt that you really need that.






            share|improve this answer















            Answers to your questions are given here:





            1. The Java™ Tutorials. Classes

            2. The Java™ Tutorials. Object-Oriented Programming Concepts


            UPD



            Car class inherits from Object. An array of Cars is narrower than an array of Objects. So roughly speaking if you store your cars in an array of objects - you will need to cast them back to cars each time you want to use an instance. I doubt that you really need that.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 2 at 14:36

























            answered Jan 2 at 14:08









            Anton HlinistyAnton Hlinisty

            98611324




            98611324













            • Don't see any reference to Object Arrays within your link

              – CuriousIndeed
              Jan 2 at 14:14






            • 1





              @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

              – Anton Hlinisty
              Jan 2 at 14:22






            • 2





              While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

              – BoarGules
              Jan 2 at 14:28











            • @BoarGules added textual explanation

              – Anton Hlinisty
              Jan 2 at 14:36



















            • Don't see any reference to Object Arrays within your link

              – CuriousIndeed
              Jan 2 at 14:14






            • 1





              @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

              – Anton Hlinisty
              Jan 2 at 14:22






            • 2





              While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

              – BoarGules
              Jan 2 at 14:28











            • @BoarGules added textual explanation

              – Anton Hlinisty
              Jan 2 at 14:36

















            Don't see any reference to Object Arrays within your link

            – CuriousIndeed
            Jan 2 at 14:14





            Don't see any reference to Object Arrays within your link

            – CuriousIndeed
            Jan 2 at 14:14




            1




            1





            @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

            – Anton Hlinisty
            Jan 2 at 14:22





            @CuriousIndeed, see the What Is Inheritance? at the second link. Consider that Car implicitly inherits from Object.

            – Anton Hlinisty
            Jan 2 at 14:22




            2




            2





            While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

            – BoarGules
            Jan 2 at 14:28





            While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

            – BoarGules
            Jan 2 at 14:28













            @BoarGules added textual explanation

            – Anton Hlinisty
            Jan 2 at 14:36





            @BoarGules added textual explanation

            – Anton Hlinisty
            Jan 2 at 14:36


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007675%2fdifference-between-object-and-array-of-specific-objects-in-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory