aspose file tools*
The moose likes Beginning Java and the fly likes Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java" Watch "Java" New topic
Author

Java

Sumesh Kumar T N
Greenhorn

Joined: Jan 26, 2005
Posts: 10
public class Hello {
public static Hello() {
System.out.println("Hello");
}

public static void main(String[] args) {
Hello hello=new Hello();
}
}

Is there any problem with this code. What is the significance of a constructor being static
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
It will not work as you cannot have static constructors in Java. A static keyword in a method makes it a member of the class in which it is declared in, so you can call it without making an instance of that object. A constructor initializes the new instance to be created, so it doesn't make sense to make it static.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Yes there is a problem with this code even this post. Please ask this in java general beginner forum.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Moving to Java in General (Beginner)...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
 
subject: Java
 
Similar Threads
help
interface methods are called...
Can we execute anything before calling main method?
public static Vs protected static
static member initialization