Download coursework and feedback details

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CSM/02/Sample Paper
1
UNIVERSITY OF SURREY ©
Msc in Internet Computing
Level M Example Examination
Module CSM02 – Internet Software Development
Time allowed - 2 hours
Autumn Semester 2005
Attempt ALL TWENTY questions. All questions are worth 5 marks.
Important: Be sure to provide a short explanation of your answer. Even in the case
where your answer is incorrect, the reasoning in your explanation can
attract marks.
24/11/05 – Paper complete.
Examiner: Prof. Paul Krause
External Examiner: Prof. Rob Hierons
SEE NEXT PAGE
CSM/02/Sample Paper
2
1. Will the following source file compile without error?
import java.io.*;
package questions;
import java.lang.*;
class ClassA { }
2. Will the following source file compile without error if it is saved with the
filename of Test2.java?
package questions;
class Test1 { }
public class Test2 { }
3. What will be the output of the following code if it is started from the
command line using java Question3 ready steady go?
public class Question3 {
public static void main(String[] args) {
System.out.println( args[2] );
}
}
4. Which of the following are legal character literals?
(a) \u0031
(b) ‘a’
(c) 9
(d) “z”
(e) 0x0065
(f) Y
5. Which of the following are legal array declarations?
(a) int [] [] myPlantIds [];
(b) char [] myChars;
(c) int [6] myPlantIds;
(d) Animal myAnimals [];
(e) Plant myPlants [7];
Continued over …
CSM/02/Sample Paper
3
6. Is the second method below a legal overloading of the first doThings( )
method? Please explain your answer.
public void deposit( int amount );
public int deposit( int amount );
7. Would the following code compile? Look very carefully!
public class Plant {
private int plantCount = 0;
public static int getPlantCount( ) {
return plantCount;
}
}
8. Which of the following are true statements?
a.
b.
c.
d.
An abstract class is allowed to have non-abstract methods.
An abstract class must have no instance fields.
An abstract class may include static abstract methods.
If a class has abstract methods, it must be declared abstract.
9. Which of the following are true statements about the private access
modifier?
(a) private means “private to the class”.
(b) private means “private to the instance”.
(c) static methods must not be marked private.
(d) abstract methods must not be marked private.
10. Which of the following statements are true about method overriding?
(a) Overriding methods are allowed to change the return type.
(b) Overriding methods are allowed to change the argument list.
(c) Overriding methods must have the same return type as the overridden
method.
(d) Overriding methods can be defined in the same class as the overridden
method.
Continued over …
CSM/02/Sample Paper
4
11. An object can be deleted by invoking its delete() method. True or False?
Explain your answer.
12. The garbage collection process ensures your application will never run out of
memory. True or False? Explain your answer.
13. Setting all of an object’s references to null guarantees that it will be garbage
collected. True or False? Explain your answer.
14. At what point in the following example code does the object passed to
method() become eligible for garbage collection?
(a) After line 10
(b) When the method finishes executing
(c) After line 5
(d) Never within this example
public class Testing {
public static void main(String[] args) {
String str = new String(“An Object”);
String str1 = (String) method(str);
str = null;
System.out.println( str1 );
}
public static Object method(Object anObject) {
Object objB = anObject;
anObject = null;
return objB;
}
15. Which class is implicitly extended by all classes in Java? Explain your answer.
(a) Class
(b) Object
(c) ClassLoader
(d) Runtime
Continued over …
CSM/02/Sample Paper
5
16. What will be the output produced by the statements below? Explain your
answer.
Boolean b = new Boolean(true);
System.out.println(b.equals(“true”));
17. What will be the result of an attempt to compile and run the following code?
public class Demo{
public static void main(String[] args) {
int i = 1;
if (i >= 0)
if (i >= 2)
if (i >= 4)
System.out.println(“big number”);
else
System.out.println(“not so big number”);
else
System.out.println(“small number”);
}
}
18. Which of the following statements are true?
(a) If an exception is thrown in try, and the matching catch block is
empty, the exception will not be considered caught and will be
propagated from a method.
(b) If an exception is thrown in try and there is a finally block but no
catch, the exception will not be considered caught and will be
propagated from a method.
(c) Only checked exceptions can be caught in a try-catch-finally
construct.
(d) If an exception is thrown in a try block, whether it is caught or not,
the statement in the try block after one causing an exception will not
be executed.
19. Given that class MyThread extends java.lang.Thread, which of the
following statements correctly instantiates a Thread object and starts the
thread?
(a) new MyThread().run();
(b) new MyThread().start();
(c) new Runnable(new MyThread()).start();
(d) new Thread(MyThread()).start();
Continued over …
CSM/02/Sample Paper
6
20. In a multithreaded application, use of synchronised code is necessary in order
to?
(a) Allow all threads to run normally.
(b) Protect shared resources from concurrent access.
(c) Control the order of execution of threads based on their priority.
(d) Make the code run faster.
(e) Convert the application to an applet.