Section 4:
Algorithm Design and Implementation
( click here for the exam objectives )
 
Question 4-1
What will be the result of compiling and running the following code ?
public class StringCheck {
    public static void main(String args[]) {
        String s = "SCJA     ";
        s.trim();
        s = s + "Exam";
        System.out.println(s);
    }
}
Select the correct answer :
a. SCJA     Exam
b. SCJA Exam
c. SCJAExam
d. Compilation fails
Answer

Question 4-2
What will be the result of compiling and running the following code ?
public class LoopCheck {
    public static void main(String args[]) {
        int i = 0;
        int x = 10;        
        while ( x > 6 ) {
            System.out.print(++i + " ");
            x--;
        }
    }
}
Select the correct answer :
a. 1 2 3 4 5
b. 0 1 2 3 4
c. 1 2 3 4
d. 0 1 2 3
e. 0 1 2 3 4
Answer

Question 4-3
Which of the following code fragments are a valid iteration statements ?
Select all correct answers :
a. for ( int i=0; i<10;i++ ) {}
b. for ( ; ; ) {}
c. for ( int i=0; i< 5; ) {i++;}
d. for ( int i=10; true; i--) {}
Answer

Question 4-4
The body of a do while loop is always executed more than one time.
Select the correct answer :
a. The statement is true
b. The statement is false
Answer

Question 4-5
Which of the following statements about the ScopeCheck class are true ?
public class ScopeCheck {        
    private String name;
    private int    age;
        
    public String call(String s) {        
        String text;
        return s;
    }
}
Select all correct answers :
a. The variables name and age are instance variables
b. The variable text is a method parameter variable
c. The variable text is a local variable
d. Compilation fails because variable text is not initialized
Answer


How do you rate this mock exam ?
very easy easy medium advanced hard
Feel free to use the feedback formular to give us detailed comments or suggestions .

 
 
 
 
last modified : 6/21/2012 - 20:38