Code:
class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if (age > 0) {
this.age = age;
} else {
System.out.println("Age must be positive.");
}
}
}
public class Main {
public static void main(String[] args) {
Person person = new Person("Absari Alif", 16);
System.out.println("Name: " + person.getName());
person.setName("Naw Shin");
System.out.println("Updated Name: " + person.getName());
System.out.println("Age: " + person.getAge());
person.setAge(21);
System.out.println("Updated Age: " + person.getAge());
}
}