What is the output of this program ?

class Literal2
{
public static void main(String[] args)
{
int i=0786;
System.out.println(i);
}
}
/*
Output:- CE[Integer number too large]
Explanation:- In octal number, only allowed digits are 0 to 7.
*/

Read more »

What is the output of this program?

class Literal1
{
public static void main(String[] args)
{
int i=012;
System.out.println(i);
}
}
/*
Output:- 10
Explanation:- A decimal number prefixed with zero(0) is called octal literal. If we print
any literal value that will print in decimal format.
*/

Read more »

What is the output of this program?

class DataType6
{
public static void main(String[] args)
{
float f=5.5;
System.out.println(f);
}
}
/*
Output:- CE[possible loss of precision]
Explanation:- "double" data type value cannot be assigned to "float" data type. 5.5 is "double" data
type value. If we prefixed "f" to "5.5" then it will become "float" value. Then we
can assigned to "float" data type and no error will be rised.
*/
Read more »

What will be output if we pass "10 20" as command line argument?

class CommandLineArg3
{
static public void main(String[] args)
{
System.out.println(args[0]+args[1]);
}
}
/*
Output:- 1020
Explanation:- Because within the main() method command line arguments are available in the form of
String and if add two strings then it will perform concatination operation instead of addition.
*/

Read more »

What is the output of this program?

class CommandLineArg2
{
static public void main(String[] args)
{
String[] alt={"X","Y","Z"};
args=alt;
for(int i=0;i<args.length;i++)
{
System.out.println(args[i]);
}
}
}
/*
Output:- X
Y
             Z
Explanation:- Reference address of args is replced by this statement "args=alt". Hence now args
will point to "X Y Z".
*/
Read more »

What will be the output if we pass "A B C" as command line argument?

class CommandLineArg1
{
static public void main(String[] args)
{
for(int i=0;i<=args.length;i++)
{
System.out.println(args[i]);
}
}
}
/*
Output:-   A
B
               C
ArrayIndexOutOfBoundsException
Explanation:- If we replace "<=" with "<" then we will not get any Runtime Exception.
*/
Read more »

Which of the following valid main() method declarations?

public static void main(String args) Invalid
public static void Main(String[] args) Invalid
public void main(String[] args) Invalid
public static int main(String[] args) Invalid
final synchronized strictfp public static int main(String[] args) Invalid
static final public synchronized strictfp void main(String[] args) Valid
public static void main(String... args) Valid
Read more »