Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
what does instantiate two instances in java means? is it the same with create two objects?
I'am sorry I'm just new to java and it's hard grasping the idea of object programming when you came from C.
MyClass myObject - new MyClass();
instantiate two instances is simple giving memory to two Objects.
instantiate two instances
In c it is equivalent to malloc
malloc
example
Object obj1; Object obj2; obj1 = new Object(); //instantiating object1 obj2 = new Object(); //instantiating object2
Add a comment
Each time you instantiate a class you create an object. If you have two instances of a class you have two objects.
Yeah, instantiate two instances means creating two objects of the class.
The short answer yes! instances = objects
Check how Java define them in the following documentation
http://docs.oracle.com/javase/tutorial/java/javaOO/
Instantiate basically means assigning memory to objects.
Object a; //Not instantiated Object b = new Object(); //Instantiated
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
MyClass myObject - new MyClass();. A "class" is basically a template; a definition. An "object instance" occupies memory, and has state. To "instantiate an instance" in Java means to "new" an object instance.