Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Select the correct answer including the respective comments for each question (in English)
1) What would happen when the following is compiled and executed. Select the one correct
answer.
2) What would happen when the following is compiled and executed. Select the one correct
answer.
class example {
int x;
int y;
String name;
public static void main(String args[]) {
example pnt = new example();
System.out.println("pnt is " + pnt.name +
" " + pnt.x + " " + pnt.y);
}
}
A. The program does not compile because x, y and name are not initialized.
B. The program throws a runtime exception as x, y, and name are used before
initialization.
C. The program prints pnt is 0 0.
D. The program prints pnt is null 0 0.
E. The program prints pnt is NULL false false
3) The initial value of an instance variable of type String which is not explicitly initialized in
the program is --. Select the one correct answer.
A. null
B. ""
C. NULL
D. 0
E. The instance variable must be explicitly assigned.
4) What would be the results of compiling and running the following class. Select the one
correct answer.
class test {
public static void main() {
System.out.println("test");
}
}
5) What is the result of compiling and running this program ? Select the one correct answer.
A. The program does not compile as k is being read without being initialized.
B. The program does not compile because of the statement k = j = i = 1;
C. The program compiles and runs printing 0.
D. The program compiles and runs printing 1.
E. The program compiles and runs printing 2.
6) What happens when the following program is compiled and run. Select the one correct
answer.
7) What happens when the following program is compiled and run. Select the one correct
answer.
9) In the following class definition, which is the first line (if any) that causes a compilation
error. Select the one correct answer.
class test {
public static void main(String args[]) {
int i,j,k,l=0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);
}
}
A. 0
B. 1
C. 2
D. 3
11) What gets displayed on the screen when the following program is compiled and run.
Select the one correct answer.
A. The class does not compile because the top level class cannot be protected.
B. The program prints "abc"
C. The program prints "abcabc"
D. The program does not compile because statement "test = test + test" is illegal.
12) Which of the following classes are derived from the Container class. Select all correct
answer.
A. Component
B. Panel
C. java.applet.Applet
D. Dialog
E. Frame
F. MenuComponent
13) Which of the following Objects can generate ActionEvent. Select all correct answer.
A. List
B. TextArea
C. CheckBoxMenuItem
D. Choice
14) Which of these classes can be added to a Component using the add method defined in
Container class. Select all correct answers.
A. Button
B. CheckBoxMenuItem
C. Menu
D. Canvas
Convert the “Kaprekar” program from console to graphic (All in English: variables, methods,
comments, classes, User Interfaces, etc).