Why this does not work?

Hi all,

I got a very basic question. Why does not the constructor not_a_public() get called in the code below?

class not_public

{

public static void main(String[] args)

{

System.out.println("Hello World!");

not_a_public nap = new not_a_public();

}

}

class not_a_public

{

void not_a_public() {

System.out.println("Not a public!!!");

}

}

Regards

Aditya

[462 byte] By [adutta_hcla] at [2007-11-27 7:51:55]
# 1

Because that's not a constructor. Constructors can't have a return type. Remove the void and it will work. You also need to make one of the classes public.

package sandbox;

public class not_public {

public static void main(String[] args) {

System.out.println("Hello World!");

not_a_public nap = new not_a_public();

}

}

class not_a_public {

not_a_public() {

System.out.println("Not a public!!!");

}

}

hunter9000a at 2007-7-12 19:33:07 > top of Java-index,Java Essentials,New To Java...
# 2
Constructors do not have a return type. Remove the "void"
Hippolytea at 2007-7-12 19:33:07 > top of Java-index,Java Essentials,New To Java...
# 3
OOPS!!!! Hate to make such mistakes.Thanks a lot for the response.......:)
adutta_hcla at 2007-7-12 19:33:07 > top of Java-index,Java Essentials,New To Java...