This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program without a main method

 
Anshul Kapoor
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any other way of creating a program without a main method ?
public class Test{
static{
System.out.println("Without a Main Method");
System.exit(1);

}
}
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on what your definition of "program" is. What you posted would not fit my definition of "program", but it is a Java class that can be executed without having a main method, yet still executes some code.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic