Java Objects | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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!

29th Apr 2018, 7:44 AM
)_)
)_) - avatar
3 Answers
+ 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.
29th Apr 2018, 9:19 AM
Jemuel Stanley
Jemuel Stanley - avatar
+ 6
Thank you💡Jemuel Stanley
29th Apr 2018, 10:16 AM
)_)
)_) - avatar
+ 1
Welcome Disorder
29th Apr 2018, 10:39 AM
Jemuel Stanley
Jemuel Stanley - avatar