0

I need to get the Object name from .display() function like "faruq unique id is blabla".. Is it possible? Is there any method to make it happen?

public class Login {
    String uniqueID;

    public String getUniqueID() {
        return uniqueID;
    }

    public void setUniqueID(String activationLink) {
        // while(true)
        // {
        this.uniqueID = activationLink + (int) (Math.random() * 1000);
        // we can check in DB whether there already exist this ID.
        // if yes,loop until its unique; else break
        // break;
        // }
    }

    public void setUniqueID(int activationLink) {
        String changed = "" + activationLink;
        setUniqueID(changed);
    }

    void display() {
        System.out.println( /* object.getName() */ this.getClass() + " unique id is " + uniqueID);
    }

}

Here's the class invoking the Real one:-

public class TestLogin {
    public static void main(String[] args) {
        Login faruq = new Login();
        Login prem = new Login();
        faruq.setUniqueID(341342);
        prem.setUniqueID("xYwkas");
        faruq.display();
        prem.display();
    }
}
vinS
  • 1,417
  • 5
  • 24
  • 37

0 Answers0