what is static setter and getter examples in java

Solutions on MaxInterview for what is static setter and getter examples in java by the best coders in the world

showing results for - "what is static setter and getter examples in java"
Julián
20 Jul 2018
1public class DataHolder
2{
3   private static String dataString;
4
5   public static String getDataString
6   {
7      return dataString;
8   }
9
10   public static void setString(String dataString)
11   {
12      this.dataString = dataString;
13   }
14}
Miranda
05 Feb 2019
1class SomeClass {
2    private static Data data;
3
4    public static void setData(String data) {
5        data = new Data(data);
6    }
7
8    public static String getData() {
9        return data.toString();
10    }
11}
12
13class Data {
14    private String data;
15
16    public Data(String data) {
17        this.data = data;
18    }
19
20    public String toString() {
21        return data;
22    }
23}
Mats
09 Oct 2019
1public class DataHolder
2{
3   public static String dataString;
4}
Jodie
31 Nov 2020
1public class DataHolder{
2  private static String dataString;
3  public static String getDataString(){
4    synchronized(DataHolder.class){
5      return DataHolder.dataString;
6    }
7  }
8
9  public static void setString(String dataString){
10    synchronized(DataHolder.class){
11      DataHolder.dataString = dataString;
12    }
13  }
14}