tags:

views:

147

answers:

3
 public class CreditCard {

   private String cardID;
   private Integer limit;
   public String ownerName;

   public void setCardlnformation(String cardID, String ownerName, Integer limit) {
     this.cardID = cardID;
     this.ownerName = ownerName;
     this.limit = limit;
    }
 }

Which is true and Why ?

A. The class is fully encapsulated.
B. The code demonstrates polymorphism.
C. The ownerName variable breaks encapsulation.
D. The cardlD and limit variables break polymorphism.
E. The setCardlnformation method breaks encapsulation

+1  A: 

Just an answer:

C. The ownerName variable breaks encapsulation.

When part of the internal state of an object (a variable) is public, any object can directly access it, thus breaking encapsulation

Bozho
+1  A: 

C. The ownerName variable breaks encapsulation.

ownerName should be declared as private and should only be accessible via a getter or setter or something like the 'setCardlnformation' method

Ren
+1  A: 

C is right - because ownerName can be modified without using any API methods. A is false because of C B, D is false, because in code there is nothing about polymorphism.

Jan Wegner