Question: (b) The code below violates the rules on encapsulation. Re-write class Pet so that encapsulation is preserved. Class Pet { String name; int age;
(b) The code below violates the rules on encapsulation. Re-write class Pet so that encapsulation is preserved. Class Pet { String name; int age; String breed; public Pet (String name, int age, String breed) { this. name name; this. age = age; this.breed breed;
Step by Step Solution
There are 3 Steps involved in it
The provided code snippet shows a class Pet with public fields name age and breed To adhere to the p... View full answer
Get step-by-step solutions from verified subject matter experts
