Given: 20. public class CreditCard { 21. 22. private String cardlD; 23. private Integer limit; 24. public String ownerName; 25. 26. public void setCardlnformation(String cardlD, 27. String ownerName, 28. Integer limit) { 29. this.cardlD = cardlD; 30. this.ownerName = ownerName; 31. this.limit = limit; 32. } 33. } Which is true?

  1. The class is fully encapsulated

  2. The ownerName variable breaks encapsulation

  3. The cardlD and limit variables break polymorphism

  4. The setCardlnformation method breaks encapsulation


Correct Option: B
Explanation:

To solve this question, the user needs to understand the concepts of encapsulation and polymorphism.

Encapsulation is the concept of hiding the implementation details of a class and making the variables and methods private to ensure that they cannot be accessed from outside the class.

Polymorphism, on the other hand, is the ability of an object to take on many forms, depending on the context in which it is used.

Now let's examine each option and determine which is true:

A. The class is fully encapsulated: This option is incorrect. While the class does have private variables (cardlD and limit), the ownerName variable is public, which means it can be accessed from outside the class. Therefore, the class is not fully encapsulated.

B. The ownerName variable breaks encapsulation: This option is correct. The ownerName variable is declared as public, which means it can be accessed and modified from outside the class. This breaks the concept of encapsulation because the implementation details of the class are not fully hidden.

C. The cardlD and limit variables break polymorphism: This option is incorrect. The cardlD and limit variables have nothing to do with polymorphism. They are private variables that can only be accessed from within the class.

D. The setCardlnformation method breaks encapsulation: This option is incorrect. The setCardlnformation method is a public method, which is used to set the values of the private variables. It does not break encapsulation because it is providing a controlled way of accessing the private variables.

Therefore, the correct answer is:

The Answer is: B

Find more quizzes: