class my_class { int a = 8; my_class() { System.out.println(a); } } public class NewClass { public static void main(String[] argue) { new my_class(); new my_class(); } }
I can not understand the two statements in the main method ( new my_class(); ).
I have never seen this statement other than the definition of an object. I know that a new keyword allocates memory for an object and assigns a reference address, but what happens in this case is completely ambiguous; allocate memory for what?
What does the new keyword do here? Regardless of this, using this operator, I can explicitly call the constructor from the main method. I could not find such a claim anywhere in a textbook or on the Internet.
source share