• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java

 
Sumesh Kumar T N
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes there is a problem with this code even this post. Please ask this in java general beginner forum.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General (Beginner)...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic