0 votes
in JAVA by
How to make a write-only class in Java?

1 Answer

0 votes
by
A class can be made write-only by making all of the fields private. The write-only class will have only setter methods which set the value passed from the main method to the private fields. We cannot read the properties of the class because there is no getter method in this class. Consider the following example.

  //A Java class which has only setter methods.    

public class Student{    

//private data member    

private String college;    

//getter method for college    

public void setCollege(String college){    

this.college=college;    

}    

}

Related questions

0 votes
asked Jan 24, 2021 in JAVA by rajeshsharma
0 votes
asked Jun 17, 2022 in JAVA by sharadyadav1986
...