Java Type Casting MCQ Questions and Answers

Java Type Casting MCQ Questions and Answers

Home | Java | Type Casting

Java Type Casting MCQ Questions and Answers: Here learn quiz questions and answers for competitive exam and test your answer each questions and download pdf of objective type questions on Java Type Casting.

Page: 1/1

1) 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;

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

3) Which of the following automatic type conversion will be possible?

4) Which of these is necessary condition for automatic type conversion in Java?

5) What is the prototype of the default constructor of this class?

      public class prototype { }

6) What is the error in this code?

      byte b = 50;
b = b * 50;

7) If an expression contains double, int, float, long, then whole expression will promoted into which of these data types?

8) What is Truncation is Java?

9) What is the output of this program?

      class char_increment      {
public static void main(String args[])
{
char c1 = 'D';
char c2 = 84;
c2++;
c1++;
System.out.println(c1 + " " + c2);
}
}

10) What is the output of this program?

      class conversion      {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}

Download MCQ PDF