October 2018
Intermediate to advanced
590 pages
15h 5m
English
Scope is about the accessibility of variables. In Java, basically, a set of curly brackets {} defines a scope, including class-level scope, method-level scope, and block-level scope.
Let's take a look at the following example in Java:
1. public class User { 2. private String name; 3. private List<String> interests; 4. 5. public User (String name, List<String> interests) {6. this.name = name;7. this.interests = interests;8. }9. 10. // Check if a user is interested in something11. public boolean isInterestedIn(String something) {12. boolean interested = false;13. for (int i = 0; i < interests.size(); i++) {14. if (interests.get(i).equals(something)) {15. interested = true;16. break;17. } 18. } 19. return interested; ...
Read now
Unlock full access