Exploring Encapsulation in Java

Report a typo

In the context of Java, consider the following code snippet:


 public class Person {
     private String name;
     private int age;

     public String getName() {
         return this.name;
     }

     public void setName(String name) {
         this.name = name;
     }

     public int getAge() {
         return this.age;
     }

     public void setAge(int age) {
         if (age > 0) {
             this.age = age;
         }
     }
}

Based on this Java code and the concept of access control and encapsulation, which of the following statements are true?

Select one or more options from the list
___

Create a free account to access the full topic