Difference between Object[] and Array of specific Objects in java
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
|
show 1 more comment
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
2
What is the difference between anObject
andCar
variable ?
– AxelH
Jan 2 at 14:01
Object
can contain anyObject
s.car
can contain instances ofcar
. 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
|
show 1 more comment
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
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
java arrays object
edited Jan 2 at 14:22
CuriousIndeed
asked Jan 2 at 14:00


CuriousIndeedCuriousIndeed
986
986
2
What is the difference between anObject
andCar
variable ?
– AxelH
Jan 2 at 14:01
Object
can contain anyObject
s.car
can contain instances ofcar
. 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
|
show 1 more comment
2
What is the difference between anObject
andCar
variable ?
– AxelH
Jan 2 at 14:01
Object
can contain anyObject
s.car
can contain instances ofcar
. 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 Object
s. car
can contain instances of car
. As you might expect.– khelwood
Jan 2 at 14:02
Object
can contain any Object
s. 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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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.
add a comment |
Answers to your questions are given here:
The Java™ Tutorials. Classes- The Java™ Tutorials. Object-Oriented Programming Concepts
UPD
Car
class inherits from Object
. An array of Car
s is narrower than an array of Object
s. 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.
Don't see any reference to Object Arrays within your link
– CuriousIndeed
Jan 2 at 14:14
1
@CuriousIndeed, see theWhat Is Inheritance?
at the second link. Consider thatCar
implicitly inherits fromObject
.
– 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
edited Jan 2 at 14:26
answered Jan 2 at 14:09


Daniel B.Daniel B.
1,2991112
1,2991112
add a comment |
add a comment |
Answers to your questions are given here:
The Java™ Tutorials. Classes- The Java™ Tutorials. Object-Oriented Programming Concepts
UPD
Car
class inherits from Object
. An array of Car
s is narrower than an array of Object
s. 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.
Don't see any reference to Object Arrays within your link
– CuriousIndeed
Jan 2 at 14:14
1
@CuriousIndeed, see theWhat Is Inheritance?
at the second link. Consider thatCar
implicitly inherits fromObject
.
– 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
add a comment |
Answers to your questions are given here:
The Java™ Tutorials. Classes- The Java™ Tutorials. Object-Oriented Programming Concepts
UPD
Car
class inherits from Object
. An array of Car
s is narrower than an array of Object
s. 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.
Don't see any reference to Object Arrays within your link
– CuriousIndeed
Jan 2 at 14:14
1
@CuriousIndeed, see theWhat Is Inheritance?
at the second link. Consider thatCar
implicitly inherits fromObject
.
– 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
add a comment |
Answers to your questions are given here:
The Java™ Tutorials. Classes- The Java™ Tutorials. Object-Oriented Programming Concepts
UPD
Car
class inherits from Object
. An array of Car
s is narrower than an array of Object
s. 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.
Answers to your questions are given here:
The Java™ Tutorials. Classes- The Java™ Tutorials. Object-Oriented Programming Concepts
UPD
Car
class inherits from Object
. An array of Car
s is narrower than an array of Object
s. 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.
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 theWhat Is Inheritance?
at the second link. Consider thatCar
implicitly inherits fromObject
.
– 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
add a comment |
Don't see any reference to Object Arrays within your link
– CuriousIndeed
Jan 2 at 14:14
1
@CuriousIndeed, see theWhat Is Inheritance?
at the second link. Consider thatCar
implicitly inherits fromObject
.
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
What is the difference between an
Object
andCar
variable ?– AxelH
Jan 2 at 14:01
Object
can contain anyObject
s.car
can contain instances ofcar
. 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