Question: b) The code below violates the rule on encapsulation. Re-write class Laptop so that encapsulation is preserved. Class Battery { private String type: private int
b) The code below violates the rule on encapsulation. Re-write class Laptop so that encapsulation is preserved. Class Battery \{ private String type: private int voltage; public Battery (String type, int voltage) \{ this.type = type: this.voltage = voltage; \} public String getType()\{return type;\} public int getVoltage ()\{return voltage; \} public void setType(String type) { this.type = type; } public void setVoltage (int voltage) \{ this.voltage = voltage; \} \} class Laptop \{ private Battery battery: " private String brand; public Laptop (Battery battery, String brand) \{ this.battery = battery; this.brand = brand; \} public Battery getBattery ()\{i\}sturn battery; \} public String getBrand () \{return brand;\}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
