Advanced Programming Exam 1
Advanced Programming Exam 1
Advanced Programming Exam 1
Part I - Circle the best answer for the following questions (40%)
1. The most time consuming stage of software development is
a. coding b. code review c. compiling d. testing and debugging
2. The most expensive component of modern computing is
a. Software b. hardware
3. Coding is low priority compared to design
a. TRUE b. FALSE
4. In object oriented programming data is
a. Primary b. secondary
5. The notion of combining state and methods in an object is called
a. inheritance b. encapsulation c. interface d. none of the above
6. An object is a class instance
a. TRUE b. FALSE
7. A class is a ____________ for objects
a. instance b. blue-print c. method
8. Package is a collection of ___
a. related classes b. related methods c. related variables
9. The key word "extends" refer to the notion of
a. class defintion b. inheritance c. state of an object
10. The relationship "is-a" is
a. inheritance b. recursion c. class containment
11. Which one of the following is not a primitive data type
a. int b. bool c. float d. char
12. Public members of a class are:
a. Accessible only by the class members
b. Accessible by all outside objects
13. Objects are _____ from classes
a. declared b. constructed
14. Which one of the following is not a primitive data type
a. int b. class c. char d.boolean
15. The following is valid code: final int x = 2; x = x + 1;
a. TRUE b. FALSE
16. A difference between private and protected member of a class makes sense when we are
dealing with
a. Defining new members of a class b. using inheritance to create new classes
c. when we want to protect private members from changes
17. An array size can be changed at run time
a. TRUE b. FALSE
f. Write a boolean method that returns true if the matrix is symmetric (i.e M[i][j]=M[j][i])
public void isSymmetric() {
for (int I=0; I<numRows; I++)
for (int j=0; j<numColumns; j++)
if (mat[I][j] != mat[j][I]) return false;
return true;
}
g. Write a complete method that will return the sum of the diagonal elements of a matrix, if
it is square.
public int diagonalSum() {
if (isSquare())
{ int sum=0;
for (int I=0; I<numRows;I++) sum += mat[I][I];
return sum;
}
else return –999;
}
. Consider the following class defintion
lpublic class PersonDB {
private Vector L=new Vector();
public PersonDB(){}
public boolean searchDB(OnePerson P){}
public boolean moveToBack(OnePerson P){}
public boolean moveToFront(OnePerson P){}
};
a. Complete the methods moveToBack(). Method should return false , if object P is not in
the list.
public boolean moveToBack(OnePerson P){
if (searchDB(P))
{ int I = L.indexOf(P);
L.remove(i);
L.addElement(P);
}
else return false;
}
b. Complete the methods moveToFront(). Method should return false , if object P is not in
the list.
public boolean moveToFront(OnePerson P){
if (searchDB(P))
{ int I = L.indexOf(P);
L.remove(i);
L.insertElementAt(P,0);
}
else return false;
}