Can anyone tell how can i put getter and setter on the below code, and what exactly getter and setter do

Anant Tyagi
public class perform{

    public static void Main(String args[]) throws IOException 
    {
        perform obj = new perform();
        obj.run();
    }
      public void run() throws IOException 
      {
          String inputfile= "c:/file_adress";
          List<String> field = null;
          String delimeter = ";";
          String line="";
          BufferedReader br = new BufferedReader(new FileReader(inputfile));
          while((line=br.readLine())!=null)
          {
              field = new ArrayList<String>();
              field=Arrays.asList(line.split(delimeter));
              for (String object : field) {

                  System.out.println( "-->" + object + "\n");
              }
          }
      }
      }

now when i try to put getter and setter on this code, by right clickin on the code and then going to source menu. it gives error - "The Operation is not applicable to the current selection. Select a field which is not declared as type variable or a type that declares such fields."

can anyone help me what changes i need to make to add getter and setter and why they are used.

kajarigd

You can add getters and setters for class variables only. In your code, the class is perform and it has two methods - Main() and run(). All the variables you are using in your code and either in Main() or run(). Hence, those are local method variables, and not class variables.

getter and setter methods allow you to efficiently manage the access of class variables by other external classes. Your local method variables won't be accessed by other external classes. Also, a local variable inside one method cannot be directly accessed in another method, even if it is inside the same class because a local variable is only alive inside the method it is declared.

Why these are needed? Please read the explanation given in this stackoverflow post - what is the point of getters and setters

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I modify the IntelliJ getter and setter code generation?

From Dev

How can I add getter and setter to PropertyDeclarationSyntax?

From Dev

How can I get @getter and @setter?

From Dev

How can I create a getter method and a setter method for a multidimensionnal array?

From Dev

How do I create getter and setter overrides?

From Dev

How do I create getter and setter overrides?

From Dev

How can I get console.log to output the getter result instead of the string "[Getter/Setter]"?

From Dev

What are getter and setter methods?

From Dev

Can I use property syntax for a Java setter without a corresponding getter?

From Dev

Python - can I wrap attribute assignment without writing a getter/setter

From Dev

Why can't I customize the getter and setter if class property is atomic?

From Dev

Can I enumerate properties that only exist as getter/setter functions?

From Dev

Can I use getter and setter in java MVC model

From Dev

Why can't I customize the getter and setter if class property is atomic?

From Dev

If Getter/Setter are replaced at compile time in java; how can their purpose be fulfilled?

From Dev

If Getter/Setter are replaced at compile time in java; how can their purpose be fulfilled?

From Dev

Why by passing it in as a parameter to a .then method, can I do bind a pre-existing getter-setter?

From Dev

Can stored property in Swift have getter and setter?

From Dev

How do I assign a getter/setter function pair in TypeScript?

From Dev

How do I specify different getter and setter accessors for a Description in Magritte?

From Dev

How do I create closures for model getter-setter in angular?

From Dev

How do I refactor getter and setter methods using retain release?

From Dev

How do I set up an inferred type list getter and setter?

From Dev

How to create getter and setter

From Dev

Can anyone tell me what exactly this code means in c#?

From Dev

How do Setter and Getter methods work?

From Dev

How to do getter and setter in array list in Android

From Dev

How to do a looping from setter getter in android?

From Dev

What is the use of placing an instance variable in .h where it wouldn't have a getter and setter ( i.e. nobody can set nor get it)?

Related Related

  1. 1

    How can I modify the IntelliJ getter and setter code generation?

  2. 2

    How can I add getter and setter to PropertyDeclarationSyntax?

  3. 3

    How can I get @getter and @setter?

  4. 4

    How can I create a getter method and a setter method for a multidimensionnal array?

  5. 5

    How do I create getter and setter overrides?

  6. 6

    How do I create getter and setter overrides?

  7. 7

    How can I get console.log to output the getter result instead of the string "[Getter/Setter]"?

  8. 8

    What are getter and setter methods?

  9. 9

    Can I use property syntax for a Java setter without a corresponding getter?

  10. 10

    Python - can I wrap attribute assignment without writing a getter/setter

  11. 11

    Why can't I customize the getter and setter if class property is atomic?

  12. 12

    Can I enumerate properties that only exist as getter/setter functions?

  13. 13

    Can I use getter and setter in java MVC model

  14. 14

    Why can't I customize the getter and setter if class property is atomic?

  15. 15

    If Getter/Setter are replaced at compile time in java; how can their purpose be fulfilled?

  16. 16

    If Getter/Setter are replaced at compile time in java; how can their purpose be fulfilled?

  17. 17

    Why by passing it in as a parameter to a .then method, can I do bind a pre-existing getter-setter?

  18. 18

    Can stored property in Swift have getter and setter?

  19. 19

    How do I assign a getter/setter function pair in TypeScript?

  20. 20

    How do I specify different getter and setter accessors for a Description in Magritte?

  21. 21

    How do I create closures for model getter-setter in angular?

  22. 22

    How do I refactor getter and setter methods using retain release?

  23. 23

    How do I set up an inferred type list getter and setter?

  24. 24

    How to create getter and setter

  25. 25

    Can anyone tell me what exactly this code means in c#?

  26. 26

    How do Setter and Getter methods work?

  27. 27

    How to do getter and setter in array list in Android

  28. 28

    How to do a looping from setter getter in android?

  29. 29

    What is the use of placing an instance variable in .h where it wouldn't have a getter and setter ( i.e. nobody can set nor get it)?

HotTag

Archive