The following code does not work because the compiler says that the function AnotherNewClass() does not exist? Why is that? Isnt a constructor just a function? Why cant a constructor function without a reference to a particular object?
class AnotherNewClass
{
public AnotherNewClass(){
System.out.println("Hello World!!");
}
public AnotherNewClass(String arg){
System.out.println("Hello World!!");
}
public static void main(String []args){
AnotherNewClass("Hello World!!");//This is the offending code; where the compiler throws an error
}
}
PS. From a few comments below I would like to clarify that I understand that I am not using the new keyword, the purpose of this question was to highlight the difference between a function and a constructor(which cannot be called WITHOUT 'new')