Tuesday, 20 May 2014

Java Data Types & Variables



1. A _________ is a basic unit of storage in Java.

A.
Identifier

B.
Variable

C.
Constant

D.
Memory


2
 . What is the default data type of a decimal number in Java?

A.
int

B.
float

C.
double

D.
long


3. What would be the output of the following program?
class PrintDefaultValues
{
    public static void main(String[] args)
    {
        byte b;
        short s;
        int i;
        long l;
        float f;
        double d;
        boolean bl;
        char c;
        System.out.println("byte="+b+" short="+s+" int="+i);
        System.out.println("long="+l+" float="+f+" double="+d);
        System.out.println("char="+c+"boolean="+bl);
    }
}

A.
byte=0 short=0 int=0
long=0 float=0.0 double=0.0
char= boolean=false

B.
byte=0 short=0 int=0
long=0 float=0.000000 double=0.000000
char= boolean=false

C.
Compilation Error

D.
None of the Above

4. What would be the output of the following program?
class PrintDefaultValues
{
    /*Global Variables*/
    byte b;
    short s;
    int i;
    long l;
    float f;
    double d;
    boolean bl;
    char c;
    public static void main(String[] args)
    {

        System.out.println("byte="+b+" short="+s+" int="+i);
        System.out.println("long="+l+" float="+f+" double="+d);
        System.out.println("char="+c+"boolean="+bl);
    }
}

A.
byte=0 short=0 int=0
long=0 float=0.0 double=0.0
char= boolean=false

B.
byte=0 short=0 int=0
long=0 float=0.000000 double=0.000000
char= boolean=false

C.
Compilation Error

D.
None of the Above

5. What would be the output of the following program?
class PrintDefaultValues
{
    static byte b;
    static short s;
    static int i;
    static long l;
    static float f;
    static double d;
    static char c;
    static boolean bl;
    public static void main(String[] args)
    {
        System.out.println("byte="+b+" short="+s+" int="+i);
        System.out.println("long="+l+" float="+f+" double="+d);
        System.out.println("char="+c+"boolean="+bl);
    }
}

A.
byte=0 short=0 int=0
long=0 float=0.0 double=0.0
char= boolean=false

B.
byte=0 short=0 int=0
long=0 float=0.000000 double=0.000000
char= boolean=false

C.
byte=0 short=0 int=0
long=0 float=0 double=0
char=null boolean=false

D.
Compilation Error


6. What would be the output of the following program?
class A
{
    public static void main(String[] args)
    {
        System.out.println("Hello World!");
        int i=0;
        if (i=0)
        {
            System.out.println("i="+i);
        }
    }
}

A.
Hello World! 
i=0

B.
Hello World!

C.
Compilation Error

D.
None of the Above

7. What would be the output of the following program?
class multipleAssignment
{
    public static void main(String[] args)
    {
        int i,j,k;
        i=j=k=10;
        System.out.println("i="+i+" j="+j+" k="+k);
    }
}

A.
i=10 j=10 k=10

B.
Compilation Error

C.
i=0 j=0 k=10

8. What would be the output of the following program?
class Sample
{
    public static void main(String[] args)
    {
        int i;
        System.out.println("i is not used in this program!");
    }
}

A.
i is not used in this program!

B.
Compilation Error

9. How can we create an unsigned int variable in Java?

A.
Can not be created

B.
unsigned int i;

C.
int i=(unsigned int) 10;

D.
int unsigned i;

10. What would be the output of the following program?
class ByteSize
{
    public static void main(String[] args)
    {
        byte b=128;
        System.out.println(b);
    }
}

A.
128

B.
-128

C.
Compilation Error

D.
None of the Above

11. What would be the output of the following program?
class ByteSize
{
    public static void main(String[] args)
    {
        byte b=127;
        System.out.println(b+1);
    }
}

A.
128

B.
-127

C.
Compilation Error

D.
None of the Above

12. What is the width and range of int in java?

A.
32 bits | -2,147,483,648 to 2,147,483,647

B.
32 bits | 0 to 4294967296

C.
16 bits | -32768 to 32767

D.
Compiler Dependent

13. What would be the output of the following program?
class CharRange
{
    public static void main(String[] args)
    {
        char ch=88;
        System.out.println(ch+" = " +(int)ch);
        ch=ch+1;
        System.out.println(ch+" = " +(int)ch);
    }
}

14. What would be the output of the following program?
class OctalPrgm
{
    public static void main(String[] args)
    {
        int i=08;
        System.out.println(i+1);
    }
}

A.
9

B.
09

C.
00

D.
Compilation Error
15. What would be the output of the following program?
class OctalPrgm
{
    public static void main(String[] args)
    {
        int i=07;
        System.out.println(++i);
        i=i+1;
        System.out.println(++i);
    }
}
16. What would be the output of the following program?
class HexPrgm
{
    public static void main(String[] args)
    {
        int i=0x10;
        System.out.println(i);
    }
}

A.
10

B.
a

C.
16





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

A.
0

B.
16

C.
17

D.
Compilation Error

18. What would be the output of the following program?
class Scope1
{
    public static void main(String args[])
    {
        int i=10;
        System.out.println(i);
        if (i==10)
        {
            int i=20;
            System.out.println(i);
        }
        System.out.println(i);
    }
}

19. What would be the output of the following program?

class Scope2
{
    public static void main(String args[])
    {
        int i=10;
        System.out.println("i="+i);
        if (i==10)
        {
            int j=20;
            i=20;
            System.out.println("i="+i+" , j="+ j);
        }
        System.out.println("i="+i+" , j="+ j);
    }
}

A.
i=10
i=20, j=20

B.
i=10
i=10,j=20

C.
Compilation Error

D.
None of the Above

20. What would be the output of the following program?
class Scope3
{
    public static void main(String args[])
    {
        for (int i=1;i<=3 ;i++ )
        {
            int y=1;
            System.out.println("i="+i+" y="+y);
            y++;
        }
    }
}

A.
i=1 y=1
i=2 y=2
i=3 y=3

B.
i=1 y=1
i=2 y=1
i=3 y=1

C.
i=1 y=1
i=1 y=1
i=1 y=1

D.
Compilation Error

No comments:

Post a Comment

Access attributes in component

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