Vous êtes sur la page 1sur 4

The Islamic University of Gaza Programming II

Faculty of Information Technology Second Semester (2016-2017)


Department of Information Midterm Exam
Technology Systems Duration Time :- 1 Hour
Instructor: - Dr. Basem O. Alijla

St. Id:- St. Name:- Mark:-

Question 1:

Multiple Choice- Choose the best answer from the choices given [1 mark for each]

1. Which of the following commands will run the compiled Java program named Welcome
A. run Welcome B. java Welcome.java
C. java Welcome D. go Welcome
2. Which of the following is a valid Java doc comment?
A. /** Comment 1 */ B. */ Comment 2 /*
C. // Comment 3 D. /* Comment 4 */
3. When an object is created, the attributes associated with the object are called
A. Instance attribute. B. Class instances.
C. Instance methods. D. Fixed attributes.
4. Another term for an object of a class is a(n)
A. access modifier B. instance
C. method D. member
5. Give the following code
public class T {
public int a ;
public T(int a) {
this.a = a;
}
public static void main(String[] args) {
T t1 = new T(2);
T t2 = new T(4);
t2 = t1;
}
}
A. checks if t1 and t2 have the same contents B. Assign the value of t1's a to the t2's a.
C. t1 and t2 refer to the same object D. Non on the above is true
6. The scope of a local variable is
A. Inside the parentheses "( )" of a method header.
B. The method in which they are defined.
C. Inside the class, but not inside any method.
D. The entire class
7. When an argument is passed by value,
A. The parameter variable holds the address of the argument.
B. The parameter variable cannot be changed.
C. The parameter variable holds a copy of the value passed to it.
D. Changes can be made to the argument variable.
8. If you do not provide initialization values for a class's numeric fields, they will
A. Cause a runtime error. B. Contain an unknown value.
C. Be automatically initialized with 0. D. Cause a compiler error.

1
9. Each time a method is invoked, the system stores parameters and local variables in an
area of memory, known as , which stores elements in last-in first-out fashion.
A. a heap B. a stack
C. an array D. storage area
10 The signature of a method consists of .
A. method name B. method name and parameter list
C. parameter list D. return type, method name, and parameter list
11. Overloading is
A. writing a method that does too much processing.
B. writing a program that is too large to fit in memory.
C. having two or more methods with the same signature.
D. having two or more methods with the same name, but different signatures.
12. A method's signature consists of
A. the method name and the parameter list.
B. the return type, the method name, and the parameter list.
C. the size of the method in memory.
D. the return type and the method name.
13. The only limitation that static methods have is
they must be declared outside of the class.
B. they cannot refer to nonstatic members of the class.
C. they can only be called from static members of the class.
D. they can refer to only nonstatic members of the class.
14. Assuming the following declaration exists:
enum Tree { OAK, MAPLE, PINE }
What will the following code display?
System.out.println(Tree.OAK);
A. OAK B. Tree.OAK
C. A memory address D. null
15. When a field is declared static, there will be
a copy of the field for each method in the class.
B. a copy of the field in each class object.
C. only one copy of the field in memory.
D. two reference copies of the field for each method in the class.

Question 2:
‫حدد االخطاء الموجوده في البرنامج التالي‬

A. Find, and describe the error in the following program “midterm1.java" [3 marks].

1. public class Midterm1 {


2. private int x ;
3. public Midterm1(int x ) {
4. this.x = x ;
5. Midterm1 a = new Midterm1(1); 6. }
7. public static void main(String[] args) {
8. Midterm1 t1 = new Midterm1(1) ;
9. System.out.println("x's value is :"+t1.x );
10. }
11. }

2
‫حدد االخطاء المحتملة في البرنامج التالي وأعد كتابته بحث يمكنك تفادي الخطأ المحتمل‬

B. Find the error that may occur in the following program, and rewrite the code in a
way that you can handle the unexpected error. [6 marks]

1. public class Midterm1 {


2. public static void main(String[] args) {
3. int myArray[] = {3,1,2,4};
4. int arrayCopy [] = new int[4];
5. for (int n : myArray)
6. arrayCopy[n] = n;
7. for (int b : arrayCopy)
8. System.out.printf("%d %n",b); 9. }
10. }

3
Question 3:
‫اطبع مخرجات البرامج التالية مع الشرح الية المخرجات بهذا الشكل‬
Show and describe the output of the following programs

A. [3 marks]

1. public class Midterm1 {


2. private static int x = 1;
3. public Midterm1(int x ) {
4. this.x = x ; 5.
}
6. public static void main(String[] args) {
7. Midterm1 t1 = new Midterm1(5) ;
8. System.out.println("x's value is :"+x );
9. System.out.println("x's value is :"+t1.x );
10. }
11. }

B. [3 marks]

1. public class Midterm1 {


2. private static int x = 1;
3. public static void main(String[] args) {
4. int x = 5;
5. method1();
6. System.out.printf(" X's value is %d%n", x);
7. method2();
8. System.out.printf(" X's value is %d%n", x); 9.
}
10. public static void method1 () {
11. int x = 25;
12. ++x;
13. System.out.printf(" X's value is %d%n", x);
14. }
15. public static void method2() {
16. x *= 10;
17. System.out.printf(" X's value is %d%n", x);
18. }
19. }

Good Luck
4

Vous aimerez peut-être aussi