2

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.

1
  • 1
    Short answer: 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. Commented Jun 8, 2014 at 3:47

5 Answers 5

2

instantiate two instances is simple giving memory to two Objects.

In c it is equivalent to malloc

example

Object obj1;
Object obj2;

obj1 = new Object(); //instantiating object1
obj2 = new Object(); //instantiating object2
Sign up to request clarification or add additional context in comments.

Comments

2

Each time you instantiate a class you create an object. If you have two instances of a class you have two objects.

Comments

1

Yeah, instantiate two instances means creating two objects of the class.

Comments

1

The short answer yes! instances = objects

Check how Java define them in the following documentation

http://docs.oracle.com/javase/tutorial/java/javaOO/

Comments

1

Instantiate basically means assigning memory to objects.

Object a; //Not instantiated
Object b = new Object(); //Instantiated

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.