Data Types And Variables(Computer Science > Java Program ) Questions and Answers

Question 1. Java is a ........... language.
  1.    weakly typed
  2.    strongly typed
  3.    moderate typed
  4.    None of these
Explanation:-
Answer: Option B. -> strongly typed

Question 2. In Java byte, short, int and long all of these are
  1.    signed
  2.    unsigned
  3.    Both of the above
  4.    None of these
Explanation:-
Answer: Option A. -> signed

Question 3. How many primitive data types are there in Java?
  1.    6
  2.    7
  3.    8
  4.    9
Explanation:-
Answer: Option C. -> 8

Question 4. Size of int in Java is
  1.    16 bit
  2.    32 bit
  3.    64 bit
  4.    Depends on execution environment
Explanation:-
Answer: Option B. -> 32 bit

Question 5. The smallest integer type is ......... and its size is ......... bits.
  1.    short, 8
  2.    byte, 8
  3.    short, 16
  4.    short, 16
Explanation:-
Answer: Option B. -> byte, 8

Question 6. Size of float and double in Java is
  1.    32 and 64
  2.    64 and 64
  3.    32 and 32
  4.    64 and 32
Explanation:-
Answer: Option A. -> 32 and 64

Question 7. Automatic type conversion in Java takes place when
  1.    Two type are compatible and size of destination type is shorter than source type.
  2.    Two type are compatible and size of destination type is equal of source type.
  3.    Two type are compatible and size of destination type is larger than source type.
  4.    All of the above
Explanation:-
Answer: Option C. -> Two type are compatible and size of destination type is larger than source type.

Question 8. Determine output:
class A{
public static void main(String args[]){
int x;
x = 10;
if(x == 10){
int y = 20;
System.out.print("x and y: "+ x + " " + y);
y = x*2;
}
y = 100;
System.out.print("x and y: " + x + " " + y);
}
}
  1.    10 20 10 100
  2.    10 20 10 20
  3.    10 20 10 10
  4.    Error
Explanation:-
Answer: Option D. -> Error

Question 9. Which of the following automatic type conversion will be possible?
  1.    short to int
  2.    byte to int
  3.    int to long
  4.    long to int
Explanation:-
Answer: Option C. -> int to long

Question 10. What is the output of the following program?
class A{
public static void main(String args[]){
byte b;
int i = 258;
double d = 325.59;
b = (byte) i;
System.out.print(b);
i = (int) d;
System.out.print(i);
b = (byte) d;
System.out.print(b);
}
}
  1.    258 325 325
  2.    258 326 326
  3.    2 325 69
  4.    Error
Explanation:-
Answer: Option C. -> 2 325 69