Xirius-BuildingJavaPrograms6-COS201.pdf

Course: COS201 • Xirius AI

1. What is the purpose of methods inside a class?

2. Why is using objects considered an abstraction in programming?

3. What is a mutator method designed to do?

4. What is the purpose of an accessor method?

5. What is the result of `Math.sqrt(x * x + y * y)` in an accessor method in class Point?

6. Which method type would you use to allow clients read-only access to an object's state?

7. What keyword is used inside an instance method to refer to the object the method was called on?

8. In the example method `public void translate(int dx, int dy)`, what kind of method is this?

9. What do instance methods operate on?

10. What happens when you call `p1.translate(11, 6)`?

11. Which statement best describes "object state"?

12. What is the correct way to call an instance method named `translate` on an object `p1` with parameters 11 and 6?

13. What is the main purpose of an instance method in a class?

14. What is an object in object-oriented programming?

15. What distinguishes an object-oriented program from a procedural program?

16. Which statement correctly creates an instance of a Point class?

17. What is the effect of calling a mutator method?

18. Which statement best describes a class in Java?

19. What is procedural programming characterized by?

20. When you call an instance method on an object, the object that the method operates on is called the:

21. How can clients modify an object's fields directly?

22. What does this code imply inside an instance method?

23. Which statement best describes the role of a client program?

24. What does the term "client program" refer to in the context of objects?

25. Why is grouping related variables into an object preferable to declaring them separately?

26. Which of the following best defines an implicit parameter?

27. Which of these is NOT a characteristic of an instance method?

28. Which keyword inside an instance method refers to the implicit parameter?

29. Which of these is a correct example of an accessor method?

30. What does the following code do?

31. What is abstraction in the context of programming?

32. What is the function of the `new` keyword in Java?

33. Which of the following best describes a mutator method?

34. If `p1` and `p2` are instances of class `Point`, which statement is true?

35. What does an object’s behavior refer to?

36. How would you modify a field `y` in object `p2` to 13?

37. Which of the following is a correct mutator method signature for `translate`?

38. In Java, what is a class defined as?

39. What syntax is used to call an instance method named `translate` on object `p1` with parameters `11` and `6`?

40. How does an object-oriented program differ from a procedural program?

41. Which of the following is true about fields in objects?

42. In the blueprint analogy, what represents the "state" of an iPod?

43. What benefit does grouping related variables into an object provide?

44. Which term describes a variable inside an object that holds part of its state?

45. What does a Java class primarily serve as in object-oriented programming?

46. How can a mutator method give clients access to code?

47. Which of the following best defines an accessor method?

48. What is a field in an object?

49. How do you access a field named `x` from an object named `p1`?

50. What is the output of calling `distanceFromOrigin()` if `x = 3` and `y = 4`?