Java Objects | Sololearn: Learn to code for FREE!

+9

Java Objects

Can you give me some insight?Is there any connection between objects that belongs to object class and an object of the heap i just thought my answer is correct in challenge Are all objects belongs to object class? my answer is false which is wrong tends to be true, i answered false i just red that an array is an object of the heap Thanks!

4/29/2018 7:44:21 AM

)_)

3 Answers

New Answer

+4

Objects of stack and objects of heap are 2 things one must understand. When you create an object using the new operator, for example Run run = new Run(20,10); it allocates memory for the myobj object on the heap. The stack memory space is used when you declare automatic variables. There is a stack memory and a heap memory, the local variable and parameters go into the stack whereas when we use 'new' it goes into the heap. It can be visualized like this: +--------------+ | | | | | | | | | | | | | | | | | | | | | | | | +--------------+ Stack Heap It is called stack because values are pushed onto it when you declare it or call a function and popped off when out of scope. For example: Run run = new Run(); -run is a reference to the heap memory address. -new allocates memory in the heap. The Compiler figures out the Run and creates a machine code that allocates the amount of memory it requires.

+6

Thank you💡Jemuel Stanley

+1

Welcome Disorder