Discussion Forum : Introduction To Methods And Streams
Question -


What is the output of this program?


class Output {
static void main(String args[])
{
int x , y = 1;
x = 10;
if(x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
Options:
A .  1
B .  2
C .  Runtime Error
D .  Compilation Error
Answer: Option D

main() method must be made public. Without main() being public java run time system 

will not be able to access main() and will not be able to execute the code.
output:
$ javac Output.java
Error: Main method not found in class Output, please define the main method as:
public static void main(String[] args)



Was this answer helpful ?
Next Question
Submit Your Solution hear:

Your email address will not be published. Required fields are marked *