Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Java 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);
}
}

What will be the output of the following Java 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);
}
}
a) 1
b) 2
c) Runtime Error
d) Compilation Error

Answer: d
Explanation: 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.

Join The Discussion