Java Programming Multiple Choice Questions - Data Types

This section focuses on the "Data types" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which of the following is smallest integer data type ?

A. int
B. byte
C. short
D. long

View Answer


2. Which of the following is not a primitive data type ?

A. byte
B. enum
C. short
D. int

View Answer


3. Integer Data type does not include following primitive data type ____________.

A. long
B. byte
C. short
D. double

View Answer


4. Which of the following data types comes under floating data types ?

A. int
B. double
C. long
D. byte

View Answer


5. Character data type cannot store following value.

A. Digit
B. Letter
C. Special Character
D. String

View Answer


6. Range of Byte Data Type is ____________.

A. -128 to 128
B. -127 to 127
C. -127 to 128
D. -128 to 127

View Answer


7. What is size of integer in Java Programming.

A. 1 Bytes
B. 2 Bytes
C. 4 Bytes
D. 8 Bytes

View Answer


8. Which of the following data type(s) can store 64 bit Value.

A. boolean
B. int
C. float
D. long

View Answer


9. Short data type has a minimum value of _____________.

A. -32768
B. -32767
C. 32768
D. 32767

View Answer


10. Default value of variable having boolean data type is ___________.

A. TRUE
B. FALSE
C. null
D. garbage

View Answer


11. What will be the output of the program?

  
class Main {  
   public static void main(String args[]) {    
         int t; 
         System.out.println(t);
    } 
}

A. 0
B. garbage value
C. compiler error
D. runtime error

View Answer


12. What will be the output of the program?

  
class Test { 
    public static void main(String[] args) {
      for(int i = 0; 0; i++) 
      {
          System.out.println(""Hello"");
          break; 
      } 
    } 
} 

A. Hello
B. Empty Output
C. Compiler error
D. Runtime error

View Answer


13. What will be the output of the program?

  
class mainclass {
    public static void main(String args[])
    {
      boolean var1 = true;
      boolean var2 = false;
      if (var1)
         System.out.println(var1);
      else
         System.out.println(var2);
    } 
}

A. 0
B. 1
C. TRUE
D. FALSE

View Answer


14. Predict the output of the following program.

class LFC {
    public static void main(String[] args)
    {
        Double object = new Double("2.4");
        int a = object.intValue();
        byte b = object.byteValue();
        float d = object.floatValue();
        double c = object.doubleValue();
        System.out.println(a + b + c + d );
 
    }
}

A. 8
B. 8.8
C. 8.800000095
D. 8

View Answer


15. Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. All statements are correct

View Answer


16. What is the output of this program?

  
class average {
        public static void main(String args[])
        {
            double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
            double result;
            result = 0;
            for (int i = 0; i<6; ++i) 
                result = result + num[i];
      System.out.print(result/6);
 
        } 
}
	

A. 16.34
B. 16.56666664
C. 16.46666667
D. 16.76666667

View Answer


17. What is the output of this program?

  
class output {
        public static void main(String args[]) 
        {
            double a, b,c;
            a = 4.0/0;
            b = 0/3.0;
            c=0/0.0;
 
      System.out.println(a);
            System.out.println(b);
            System.out.println(c);
        } 
}
	

A. Infinity
B. 0
C. NaN
D. all of the mentioned

View Answer


18. What will be the output of the program?

  
class increment {
        public static void main(String args[]) 
        {      
             int g = 4;
             System.out.print(++g * 8);
        }
}
	

A. 32
B. 36
C. 40
D. 48

View Answer


19. What will be the output of the program?

  
class area {
        public static void main(String args[]) 
        {   
             double r, pi, a;
             r = 9.8;
             pi = 3.14;
             a = pi * r * r;
             System.out.println(a);
        } 
}
	

A. 301.5656
B. 301
C. 301.56
D. 301.57

View Answer


20. What will be the output of the program?

      
class increment {
        public static void main(String args[]) 
        {  
             int g = 6;
             System.out.print(--g * 8);
        }
}
	

A. 48
B. 40
C. 56
D. 44

View Answer


21. What is the range of short data type in Java?

A. -128 to 127
B. -32768 to 32767
C. -2147483648 to 2147483647
D. None of the mentioned

View Answer


22. Which of the following are legal lines of Java code?   1. int w = (int)888.8;   2. byte x = (byte)100L;   3. long y = (byte)100;   4. byte z = (byte)100L;

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. All statements are correct

View Answer


23. An expression involving byte, int, and literal numbers is promoted to which of these?

A. int
B. byte
C. long
D. float

View Answer


24. Which of these literals can be contained in float data type variable?

A. -1.7e+308
B. -3.4E+38
C. +1.7e+308
D. -3.4E+50

View Answer


25. Which data type value is returned by all transcendental math functions?

A. int
B. float
C. double
D. long

View Answer


26. Which of these coding types is used for data type characters in Java?

A. ASCII
B. ISO-LATIN-1
C. UNICODE
D. None of the mentioned

View Answer


27. Which one is a valid declaration of a boolean?

A. boolean b1 = 1;
B. boolean b2 = false;
C. boolean b3 = false;
D. boolean b4 = true

View Answer


28. What is the output of this program?

  
class array_output {
   public static void main(String args[])
     {
       char array_variable [] = new char[10];
       for (int i = 0; i < 10; ++i) {
            array_variable[i] = 'i';
            System.out.print(array_variable[i] + """" );
            i++;
       }
    } 
}
		   

A. i i i i i
B. 0 1 2 3 4
C. i j k l m
D. None of the mentioned

View Answer


29. Which of these is long data type literal?

A. 0x99fffL
B. ABCDEFG
C. 0x99fffa
D. 99671246

View Answer


30. Which of these can be returned by the operator &?

A. Integer
B. Boolean
C. Character
D. Integer or Boolean

View Answer





Also check :


Discussion


* You must be logged in to add comment.