To create a new object from a class Student in Java we use normally the following statement
Student std = new Student();
I've read that the new operator creates the new object by allocating memory space in the heap, however I read also that the calling constructor Student() creates it.
So, its kind of confusing. Which one is creating the object std? Is it the new operator or the default constructor?
newjust tells the compiler to create instructions for instantiating an object, not really an operator.new Student()invokes the constructor. The two things you're asking about are actually the same thing.newallocates the memory; the constructor initializes the object.