0

Does an object created under a static method also becomes static?

6th Apr 2020, 8:49 PM
Sagar Gupta
Sagar Gupta - avatar
7 Answers
+ 1
Sagar Gupta try to come up with a code which you did not understand or something similar because it will be difficult to answer a question with a broad scope. I might not be able to give an accurate answer is all I'm saying. Hope you understand.
6th Apr 2020, 10:27 PM
Avinesh
Avinesh - avatar
+ 3
Yes, obj has the address of object. To assign address of another object to obj, you can simply write : obj=new Object () ; Check out this code for better understanding : https://code.sololearn.com/cE2u3qNKqFJ3/?ref=app
7th Apr 2020, 9:26 PM
Himani
+ 2
No, an object created inside a static method doesn't become static by default and is similar to normal instantiation. You use the static keyword to make a reference variable static.
6th Apr 2020, 9:58 PM
Avinesh
Avinesh - avatar
+ 1
Understand the difference between a reference and an actual object. Object obj = new Object(); Here obj is a reference and new Object() is the actual object which is created in the heap memory.
6th Apr 2020, 10:40 PM
Avinesh
Avinesh - avatar
0
Thanks avinesh..i have so much of confusion like which all classes and methods can use an object created in a particular class ?
6th Apr 2020, 10:03 PM
Sagar Gupta
Sagar Gupta - avatar
0
Avinesh so this reference obj1 has address of new object()? And what if we want to assign a new address to same obj1?
6th Apr 2020, 10:46 PM
Sagar Gupta
Sagar Gupta - avatar
0
Himani hey thanks, but can obj point at object of another class object apart from the class its already refering to? And also tell me what are normal class instances used for? Like if simple we create an instance temp p; ...what is the significance of this p.
7th Apr 2020, 9:44 PM
Sagar Gupta
Sagar Gupta - avatar