Review Questions

4.8 Which one of these is a valid method declaration?

Select the one correct answer.

  1. void method1 { /* ... */ }

  2. void method2() { /* ... */ }

  3. void method3(void) { /* ... */ }

  4. method4() { /* ... */ }

  5. method5(void) { /* ... */ }

4.9 Given the following code, which statements can be placed at the indicated position without causing compilation errors?
public class ThisUsage {
    int planets;
    static int suns;
    public void gaze() {
        int i;
        // ... insert statements here ...
    }
}

Select the three correct answers.

  1. i = this.planets;

  2. i = this.suns;

  3. this = new ThisUsage();

  4. this.i = 4;

  5. this.suns = planets;

4.10 Given the following pairs of method declarations, ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.