Hello,
here some questions about the first bonus
test:
question 36:
What is the output of the following program?
1: public class Supper {
2: public static void eat() throws IOException {
3: try {
4: System.out.print("1");
5: throw new IOException();
6: }catch(IOException e) {
7: System.out.println("2");
8: throw e;
9: }finally {
10: System.out.println("3");
11: }
12: }
13: public static void main(
String [] args) {
14: eat();
15: System.out.println("4");
16: }
17: }
the code does not compile, but for me it is because java.io.* is not imported (write throws IOExcepiton doesnot compile)
in the test, they say: Because main() neither handles nor declares the IOException...
which is also true
question 39:
Which of the following are true of the following code? (Choose all that apply)
1: public class Giraffe {
2: public int height;
3: public int getHeight() {
4: return height;
5: }
6: public void setHeight(int height) {
7: this.height = height;
8: }
9: }
A. This class currently exhibits data encapsulation.
B. This class currently exhibits immutability.
C. Making line 2 private would exhibit data encapsulation.
D. Making line 2 private would exhibit immutability.
E. Making line 2 private and removing lines 6–8 would exhibit data encapsulation.
F. Making line 2 private and removing lines 6–8 would exhibit immutability
I choose C but the answer is:
C, E, F.
Data encapsulation requires private instance variables. Although setters are allowed in an encapsulated class, they are not required. Immutability requires private instance variables and no setters.
I am really confused about this one because I learned that a good encapsulation is:
- Declare the variables of a class as private.
- Provide public setter and getter methods to modify and view the variables values.
and immutability: remove setters and use constructors
question 46:
Q. 46 Which of the following are true statements? (Choose all that apply)
A. do while loops can execute the loop body exactly zero times.
B. do while loops contain an increment clause.
C. for loops can execute the loop body exactly zero times.
D. for loops contain an increment clause.
E. while loops can execute the loop body exactly zero times.
F. while loops contain an increment clause.
I choose C and E
but it is C, D and E
I don t understand why D, it can also be a decrement or another kind of update statement, no?
thank you for your help,
I have the exam in a week and I am really confused about those 3 questions.
Ana