Tuesday, 20 May 2014

Java Interview Operator Questions



What is the output of the following program?
class Operators1
{
    public static void main(String[] args)  
  {
        int i=0;
        System.out.println(i++);
        System.out.println(i);
        System.out.println(++i);
    }
}

A.
0 0 1

B.
0 1 2

C.
1 1 1

D.
1 1 2

E.
Compilation Error


What is the output of the following program?
class Operators2
{
    public static void main(String[] args)
    {
        int i=0;
        System.out.println(i--);
        System.out.println(i);
        System.out.println(--i);
    }
}

A.
0 0 -1

B.
0 -1 -2

C.
-1 -1 -2

D.
-1 -1 -1

E.
Compilation Error



What is the output of the following program?
class Operators1
{
    public static void main(String[] args)
    {
        int i=0;
        System.out.println("i--="+i--+" , --i="+ --i);
    }
}

A.
i-- = 0, --i=-2

B.
i-- = -1, --i= -1

C.
i-- = -1, --i =-2

D.
None of the Above


What is the output of the following program?
class ModulusOperators1
{
    public static void main(String[] args)
    {
        float f=7.5f;
        System.out.println("7.5 % 2 ="+ f%2);
    }
}

A.
1

B.
Compilation Error: Modulus operator can not be applied on Floating Point Numbers

C.
1.5

D.
None of the Above



What is the output of the following program?
class ModulusOperators1
{
    public static void main(String[] args)
    {
        System.out.println("-8%3="+ -8%3);
        System.out.println("10%-3="+ 10%-3);
        System.out.println("-7%-3="+ -7%-3);
    }
}

A.
2 -1 -1

B.
-2 -1 1

C.
-2 1 -1

D.
-2 1 1
















No comments:

Post a Comment

Access attributes in component

NOTE: To access an attribute in a  component , use expressions as  {! v.<Attribute Name>} . ----------------------------------------...