Answer:
The code to this question can be given as:
class Sample //define class Sample.
{
//define private member.
private int count;
private String name;
Sample(int count, String name) //define parameterized constructor.
{
this.count = count; //holding values.
this.name = name;
}
public int getCount() //define function with returntype.
{
return count;
}
public String getName() //define function with returntype.
{
return name;
}
public void setCount(int count) //define function with no returntype.
{
this.count = count;
}
public void setName(String name) //define function with no returntype.
{
this.name = name;
}
}
Explanation:
In the above code firstly we define the class that is Sample. In this class, we define two variable that is not public. Then we define the constructor. This code we parameterized constructor because it takes the values as a parameter. To assign the value in the constructor we use this keyword. Then we used the get and set method. when we use get method because it returns a value (getcount and getname). When we use the set method it does not return any value (setcount and setname).