OK This q was from Dan's exam..
I'm wondering as in a lot of questions.. we may need to use a char as int like in this q.. are we supposed to know what is the representation of 'a' as an int?? Am I missing something..
class Sienna {
static double a;
static float b;
static int c;
static char d;
public static void main(
String[] args) {
a = b = c = d = 'a';
System.out.println(a+b+c+d == 4 * 'a');
}
}
What is the result of attempting to compile and run the above program?
a. Prints: true
b. Prints: false
c. Compiler error.
d. Run time error.
e. None of the above.
THIS question is from Green's mock exam.. The correct answer includes the choice 1, i chose only 2 and 4. the first one wont that give a compile error coz the assignment operator has least precedence this means that 1/3 evaluated first. the value will be a decimal which by default will be considered double and assigning double to float is a compile error!
Which of the following are legal statements?
1) float f=1/3;
2) int i=1/3;
3) float f=1.01;
4) double d=999d;
Comments appreciated!! Thanks
