+ 1
In Java, can commands exist without methods?
Sounds foolish though but I need to ask, to be rest-assured. Would appreciate your response.
8 Respostas
+ 9
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.
+ 5
Raj Chhatrala 👍
Probably, I think so.
+ 3
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.
+ 3
Danijel Ivanović maybe he means functions(block of code).
+ 2
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) {
}
}
+ 2
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
+ 1
Thanks Raj, now I understand that a minimal program must contain at least one class and a function/method.
0
Taste, you are trying to explain a problem with another problem. Thanks though