0

I have a class called "setup" that has a method that returns a string

public class Setup{
    public String getPW(){ return "pAssWord";}
}

I imported "Setup", tried to assign it to private static String, and then the system throws this error.

public class Something {

    private Setup v_var= new Setup();
    private static String password = v_var.getPW();
}

It accepts the hardcoded string, but not method called String. Can someone explain me a logic behind this?

sayhaha
  • 769
  • 3
  • 12
  • 25
  • 2
    `password` is `static` but `v_var` is not. You either need to make `v_var` `static` or `password` not `static`. I'm not sure I see the point of what you're doing, but that's just me. – MadProgrammer Jul 23 '14 at 01:05

1 Answers1

0

var_v is an instance variable. Each instance of your class would have a different value for this var. password is a static member, and is the same for all instances of your class. That's why you can't assign to it a value that is specific to an instance.

Eran
  • 387,369
  • 54
  • 702
  • 768