answersLogoWhite

0


Best Answer

the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Yes. The return statement simply says to return. The void type on the method declares what type the function will return with, and void says that the function will not return with a value, so return by itself is valid, but return {some value} is not.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can return statement be in a void method in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why use void in main of java?

No. void is not a data type. It is mandatory for all java methods to return something and if it is not going to return anything, we have to mark the method with a "void" return type to let the JVM know that it must not expect anything from the method.


Is 'void' a data type in java?

No. The void keyword is used to signify that a method will not return any objects. For example, if you type in "double", you'll need a return statement that has a double. So "void" means that there will be nothing returned.


What does a void method do?

In Java, this keyword is used to specify that the method has no return value.


Why should the java main method has the return type as void?

A void method is one that returns no value. The Java main() method is the first method to be called, therefore it doesn't need to return a value to another Java method, therefore it is declared as void. If something needs to be returned to the operating system, this is done differently, not by "returning a value" in the sense of Java.


Void in java?

Void is a keyword in Java. It is always used in method declarations. When used in the line that declares a method, it signifies the fact that the method will not return any value. The JVM will not expect the method to return anything. Ex: public static void main(String[] args) {}


What is the meaning of java void keyword?

The void keyword is used to show that a method will not return a value. // no return type public void setX(int x) { this.x = x; } // returns an int public int getX() { return x; }


Why do you write void to the first of main?

Because main is the first method being executed, the Java Virtual Machine cannot expect any return values from this method. Since void is the term used to refer to a variable that does not return any value, we use the key word void for the method signature of the main method


Can you take return type in void?

a void has no return statement. If that is what ur asking


What value is return by int main method?

1. A method declared as "int" returns an int value. 2. The main() method in Java is not declared as "int", but as "void", meaning it returns no value.


What is polymorphism in programming?

Polymorphism is the method in which a java program can have more than one function(or method) with the same name but different method signatures(different parameters or return type). possible allowance: void s() void s(int a) void s(int a,int b) void s(float a) int s()


Can the void run method be declared as private?

Sure you can. The run method is just another java method that you can modify to be private or protected or have return types as Strings etc. But, this run method will not be invoked when you start the thread. Only the default public void run() will be invoked when you do a thread.start()


Difference in using a method that return value and method that does not return value in object orinted programming?

A method that return a value should have a return statement. The method signature should indicate the type of return value. While in the case of a method that does not return a value should not have a return statement and in the signature, the return type is void. When using a method that doesn't return a value, a programmer can not get a value from that function, but instead, it can only change variable values and run other methods.