Java objective questions on automatic type promotion and answers
(1)
public class TypeConversion {
public static void main(String[] args) {
{
final int a='\15';
System.out.println(a);
}
int a=25;byte b=0100;
a=a+b;
System.out.println(a);
}
}
What will output when you compile and run the above code?
(a)15
125
(b)13
89
(c)Run time exception
(d) Compiler error
(2)
public class TypeConversion {
public static void main(String[] args) {
float f=12e-1F;
final long l=12L;
f=f+l;
System.out.println(f);
}
}
What will output when you compile and run the above code?
(a)18.9
(b)13.2
(c)Run time exception
(d) Compiler error
Answer: (b)
(3)
public class TypeConversion {
public static void main(String[] args) {
char a=5;
short b=-++a;
System.out.println(b);
}
}
What will output when you compile and run the above code?
(a)-4
(b)-5
(c)-6
(d) Compiler error
Answer: (d)
(4)
public class TypeConversion {
public static void main(String[] args) {
boolean b=11>=11;
String str=(String)b;
System.out.println(str);
}
}
What will output when you compile and run the above code?
(a)true
(b)false
(c)”true”
(d) Compiler error
Answer: (d)
(5)
public class TypeConversion {
public static void main(String[] args) {
byte b=016;
short s=0x16;
char c='\16';
int a=b+s+c;
System.out.println(a);
}
}
What will output when you compile and run the above code?
(a)48
(b)50
(c)Run time exception
(d) Compiler error
Answer: (b)
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
No comments:
Post a Comment