Error In code | SoloLearn: Learn to code for FREE!

0

Error In code

Why in this code output is No output but I coded it's to give output Test. https://code.sololearn.com/c115RETPd09n/?ref=app

11/30/2020 4:43:31 AM

Vikash Godara

8 Answers

New Answer

+3

There is no main method. Hence no entry point. Hence no call to test. Hence no output.

+6

Vikash Godara first complete your full java then you are able to make java programs.... public class Program { public static void main(String[] args) { System.out.print("Hello"); } }

+5

Coder Kitten yup!! Without using main function the programs will not compiles... I also tried to run in java N-IDE apk But that didn't work And i got the errors...

+4

Coder Kitten but visit this site,here shown we can execute java program without using main method and by using static block how? But that code is not working on sololearn... https://www.tutorialspoint.com/can-we-execute-a-java-program-without-a-main-method

+3

Yes, main is required. But only once per program; it is where the program starts, often referred to as the "entry point". You may keep your Test class as is as utility class and add a main program class: public class Program { public static void main(String... args) { Test.test(args); } } Then the program starts with main which calls test in Test passing on the arguments. Anyway, there has to be an entry point somewhere in your program.

+3

Oh, yes, i never think of static blocks. They are not used to avoid a main method, hence they always slip my mind. It is one of these things that a language allows to do but no-one does it. So, i stick by my statement that a main method is required. The language is designed that way and static block were not meant to be used to erradicate main from java progams. And i think a main function is still necessary or the program won't even compile 🤔

+2

You need to have the main method Without main You may have n number of functions which won't show any ouput... You need to add Like public static void main(String args[]) And then you may proceed to print

+1

Coder Kitten Why I can't change it? Is main required for every code in java?