answersLogoWhite

0

Java program without main

We need a main method for executing a program.

But YES we can write a program without using main() method.

TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.
TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main method

Whoa!!!!! we are done.


;)

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


Write a program to find the product of two numbers using Halving and Doubling method?

i need this answer


Write c program to print palindrome using string without using strrev strlen strcam?

sdfdg


Is it possible to write a C program without using preprocesser directives?

Technically yes, practically no.


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Can you write a program without using any semicolon inside the main function?

not possible dude


How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?

To swap two variables without using a third variable, use exclusive or manipulation... a ^= b; b ^= a; a ^= b;


How do you write a program in C to swap two variables without using the third one using XOR?

a=a^b; b=a^b; a=a^b;


Can you write a program without main in c?

Certainly, you can write a program without main, but you cannot build an executable from it, if that is okay with you.


How do you write java program using two main method?

When you start your xxxx.class it will execute its 'public static void main (String args[])' method. Any other main methods won't be executed, only if your program explicitly calls them.


Write a sample program using ASPNET explaining all the syntax and semantics of the program?

write a sample program using asp.net explaining all the syntax and semantics of the program


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?