Vote count:
0
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!!");
}
}
asked 1 min ago
1 Answer
Vote count:
0
It can, but you will need the new keyword.
new AnotherNewClass("Hello World!!");
answered 11 secs ago
Aucun commentaire:
Enregistrer un commentaire