Multiple choice technology programming languages

You should add the static keyword in the place of ? in Line ________ in the following code:

  1 public class Test {   2 private int age;  3   4 public ? int square(int n) {   5 return n * n;  6 }  7  8 public ? int getAge() {  9 }  10}

  1. in line 4

  2. in line 8

  3. in both line 4 and line 8

  4. none

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The square method in line 4 only depends on its parameter n and doesn't access any instance variables of the class, making it a perfect candidate for a static utility method. Conversely, getAge in line 8 returns the instance field age, meaning it requires an object instance and cannot be declared static.