In: Computer Science
class Pen {
private int id;
private String color;
public Pen() {
id = 0;
color = "";
}
public Pen(int aId, String aColor) {
super();
id = aId;
color = aColor;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param aId
* the id to set
*/
public void setId(int aId) {
id = aId;
}
/**
* @return the color
*/
public String getColor() {
return color;
}
/**
* @param aColor
* the color to set
*/
public void setColor(String aColor) {
color = aColor;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Id : " + id + ", Color : "
+ color;
}
}
public class PenTester {
public static void main(String[] args) {
Pen P1 = new Pen();
Pen P2 = new Pen();
System.out.println(P1);
System.out.println(P2);
Pen P3 = new Pen(1, "Red");
P3.setId(2);
System.out.println("P3 Id : " +
P3.getId());
}
}

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me