In Java, can commands exist without methods? | Sololearn: Learn to code for FREE!


In Java, can commands exist without methods?

Sounds foolish though but I need to ask, to be rest-assured. Would appreciate your response.

12/17/2018 3:33:19 PM


8 Answers

New Answer


You are using methods when you use System.out.print( ); & System.out.println( ); There are two basic types of methods:  • Build-in methods are part of the compiler package, such as System.out.println( ); & System.exit(0);  • User-defined methods are created by you, the programmer. These methods take-on names that you assign to them and perform tasks that you create.


Raj Chhatrala 👍 Probably, I think so.


I don't actually understand your question. But what I know is that, in most of the programming languages every statement must be wrapped inside a method or function or maybe a class. You can not execute anything without using method. Because most of the programming languages starts with main method.


Danijel Ivanović maybe he means functions(block of code).


I dont really understand the question, but Maybe you can, check this out. public class Program { static{ System.out.println("surprise ! :D"); } public static void main(String[] args) { } }


Thats a static block You were asking about command without method right ? My example show that you can execute a block of code with out any method. A static block will run when the class is loaded. Sorry for not give much explaination :D


Thanks Raj, now I understand that a minimal program must contain at least one class and a function/method.


Taste, you are trying to explain a problem with another problem. Thanks though