1. What is the main reason for making a variable private and providing public setters and getters instead?
2. Why should variables be declared private in an encapsulated class?
3. What kind of control does encapsulation offer over fields of a class?
4. Can a variable be made read-only using encapsulation?
5. What happens if you try to access a private variable directly from outside its class without getters or setters?
6. In the example, what is the output of the statement `System.out.print("Name : " + encap.getName() + " Age : " + encap.getAge());` if name is "James" and age is 20?
7. Consider a class variable declared as `private int age;`. How do you correctly access its value from another class?
8. What happens if you declare variables as public instead of private?
9. Encapsulation helps to achieve which of the following aspects of OOP?
10. How do setters and getters contribute to data validation in encapsulation?
11. Which of the following correctly defines a setter method for a variable `price` of type `double`?
12. According to the example, what is the effect of calling `setAge(20)` on an `EncapTest` object?
13. What is the output of the program when `setName("James")` and `setAge(20)` are called?
14. What is the main advantage of using getter and setter methods?
15. What would be the proper access modifier for the method getName() in the given example?
16. Which keyword defines a class level variable that can’t be accessed from outside the class directly?
17. Which access modifier is recommended for instance variables to achieve encapsulation?
18. What methods are used to modify the values of private variables in Java encapsulation?
19. How does encapsulation help in Java programming?
20. Can encapsulation improve modularity of the software?
21. What access modifier is typically used for variables to achieve encapsulation in Java?
22. Which of the following is NOT a fundamental concept of Object-Oriented Programming (OOP)?
23. How can encapsulation help in making fields write-only?
24. If you want to restrict access to a variable but allow reading it, which method do you provide?
25. Why is encapsulation also known as data hiding?
26. In the example provided, what access modifier is used for the variables `name`, `idNum`, and `age`?
27. How do you define a getter method for a private integer variable called age?
28. If you want to restrict access to a class’s variable, what is the best practice in Java encapsulation?
29. How can other classes access private variables of a class in encapsulation?
30. Which statement about encapsulation is true?
31. What is encapsulation in Java?
32. How can encapsulation help in making fields read-only?
33. What is the relationship between encapsulation and the other OOP concepts mentioned (inheritance, polymorphism, abstraction)?
34. Which of these is true regarding methods in encapsulation?
35. What is the default return type of setter methods in Java encapsulation?
36. Suppose a class has private String idNum. Which setter method signature is correct?
37. Why are getter and setter methods important in encapsulation?
38. What type of method is the setter method for a variable name of type String?
39. Which of the following best describes data hiding in Java encapsulation?
40. Which of the following is an example of a getter method name for Java variable `idNum`?
41. What will happen if no getter method is provided for a private variable?
42. Which of the following statements is true regarding the setter methods in the example?
43. Which principle is illustrated by wrapping data and methods in a single unit?
44. How do you achieve encapsulation in Java?
45. If a class has private variables but no getter or setter methods, what is the impact on other classes?
46. Which of the following keywords is used to declare instance variables for encapsulation?
47. What is encapsulation in Java primarily used for?
48. Which of the following is NOT a benefit of encapsulation?
49. One benefit of encapsulation is that a class can have total control over what is stored in its fields. How is this control typically enforced?
50. What are the public methods that provide read and write access to private variables called?