0% found this document useful (0 votes)
2 views

lab-6.code

Uploaded by

Habib Hawlader
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

lab-6.code

Uploaded by

Habib Hawlader
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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());

}
}

You might also like