Assessment 1 Questions - Java
Assessment 1 Questions - Java
Time = 40 min.
Marks= 1*9= 9 , 2*3= 6
2. super()is used to
5. Which of the following methods is called by the garbage collector before the object is
garbage collected?
7. What gets printed when the following program is compiled and run? Select the one correct
answer.
class test {
int i;
do {
i++;
System.out.println(i);
class xyz {
static int i;
while (i < 0) {
i--;
}
System.out.println(i);
}
a. The program does not compile. B. The program compiles but does not run.
C . The program compiles and runs but does not print anything. D. The program prints 0.
9. Given the following declarations, which of the assignments given in the options below would
compile. Select the two correct answers.
int i = 5;
boolean t = true;
float f = 2.3F;
double d = 2.3;
a. t = (boolean) i;
b. f = d;
c. d = i;
d. i = 5;
e. f = 2.8;
10 . Which declaration of the main method below would allow a class to be started as a
standalone program. Select the one correct answer.
11. Which of the following is true. Select the two correct answers.
12. Which of the following are legal array declarations. Select the three correct answers.
a. int i[5][];
b. int i[][];
c. int []i[];
d. int i[5][5];
e. int[][] a;
13. Which of the following are legal identifier names in Java. Select the two correct answers.
a. %abcd
b. $abcd
c. 1abcd
d. package
_a_long_name
14. What all gets printed when the following code is compiled and run? Select the three
correct answers.
a. i=0 j=0
b. i=0 j=1
c. i=0 j=2
d. i=1 j=0
e. i=1 j=1
f. i=1 j=2
g. i=2 j=0
h. i=2 j=1
i. i=2 j=2
15. Name the access modifier which when used with a method, makes it available to all the
classes in the same package and to all the subclasses of the class.
a. Public
b. Protected
c. Private
d. package
Descriptive Question:
1. Design an abstract class called Shape which contains an abstract method getArea().
Design two derived classes Reactangle and Circle and get their areas using dynamic
polymorphism.