Computing Magazine

Java Operators and Assignments- Quiz

Posted on the 16 April 2012 by In7rud3r

simplest way to convert the character value in c into an int? Select the one correct answer.
int i = c;
int i = (int) c;
int i = Character.getNumericValue(c);
What will be the result of attempting to compile and run the following class?
public class Assignment {
public static void main(String[] args) {
int a, b, c;
b = 10;
a = b = c = 20;
System.out.println(a);
}
}
Select the one correct answer.
The code will fail to compile, since the compiler will recognize that the variable c in the assignment statement a = b = c = 20; has not been initialized.
The code will fail to compile because the assignment statementa = b = c = 20; is illegal.
The code will compile correctly and will display1 0 when run.
The code will compile correctly and will display2 0 when run.
What will be the result of attempting to compile and run the following program?
public class MyClass {
public static void main(String[] args) {
String a, b, c;
c = new String("mouse");
a = new String("cat");
b = a;
a = new String("dog");
c = b;
System.out.println(c);
}
}
Select the one correct answer.
The program will fail to compile.
The program will print mouse when run.
The program will print cat when run.
The program will print dog when run.
The program will randomly print either cat or dog when run.
What is the value of the expression (1 / 2 + 3 / 2 + 0.1)? Select the one correct answer.
1
1.1
1.6
2
2.1
What will be the result of attempting to compile and run the following program?
public class Integers {
public static void main(String[] args) {
System.out.println(0x10 + 10 + 010);
}
}
Select the one correct answer.
The program will not compile. The compiler will complain about the expression 0x10 + 10 + 010.
When run, the program will print 28.
When run, the program will print 30.
When run, the program will print 34.
When run, the program will print 36.
When run, the program will print 101010.
What is the value of evaluating the following expression (- -1-3 * 10 / 5-1)? Select the one correct answer.
–8
–6
7
8
10
None of the above.
What happens when you try to compile and run the following program
public class Prog1 {
public static void main(String[] args) {
int k = 1;
int i = ++k + k++ + + k;
System.out.println(i);
}
}
Select the one correct answer.
The program will not compile. The compiler will complain about the expression ++k + k++ + + k.
The program will compile and will print the value3 when run.
The program will compile and will print the value4 when run.
The program will compile and will print the value7 when run.
The program will compile and will print the value8 when run.
Which is the first incorrect line that will cause a compile time error in the following program?
public class MyClass {
public static void main(String[] args) {
char c;
int i;
c = 'a'; // (1)
i = c; // (2)
i++; // (3)
c = i; // (4)
c++; // (5)
}
}
Select the one correct answer.
The line labeled (1)e. f. None of the lines are incorrect. The program will compile just fine.
The line labeled (2)
The line labeled (3)
The line labeled (4)
The line labeled (5)
None of the lines are incorrect. The program will compile just fine.
" />


Back to Featured Articles on Logo Paperblog

Magazine