• 15 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 3/28/24

Check what you remember about clean methods!

Evaluated skills

  • Describe how to write clean and maintainable code using methods in Java
  • Question 1

    What value will the static variable count have after the execution of the following code snippet?

    public class FancyWatch {
        static int count = 0;
        int usages = 0;
    
        public FancyWatch() {
            count+=1;
        }
        
        public void wear() {
            this.usages += 1;
        }
    
        public static void main(String[] args) {
            FancyWatch myWatch = new FancyWatch();
            myWatch.wear();
    
            FancyWatch joeWatch = new FancyWatch();
            for (int i=0;i<5;i++) {
                joeWatch.wear();
            }
    
            FancyWatch jennyWatch = new FancyWatch();
        }
    }
    
    • 3

    • 4

    • 5

    • 6

  • Question 2

    Which the following statements are true regarding parameters and return values of a function?

    Careful, there are several correct answers.
    • Parameters of a function are variables defined inside a method signature as being necessary input for performing a task.

    • Arguments are values sent to a method.

    • Return values are the output, or in other words, the result that a function needs to return.

    • Parameters and return values are mandatory in functions.

  • Question 3

    Check out the following code snippet: 

    public static int transform(int a, int b) {
            int x = a + b;
            int y = x * 2;
            return y;
        }
        
        public static void main(String[] args) {
            int x = 1;
            int y = 10;
            x = transform(x, y);
            y = transform(y, x);
        }
    

    What will be the values of the variables x and y by the end of the execution?

    • x -> 1, y -> 10

    • x -> 22, y -> 64

    • x -> 64, y -> 22

    • x -> 1, y -> 64

Ever considered an OpenClassrooms diploma?
  • Up to 100% of your training program funded
  • Flexible start date
  • Career-focused projects
  • Individual mentoring
Find the training program and funding option that suits you best