Calling a boolean Attribute from another class

Sharky Forums


Results 1 to 2 of 2

Thread: Calling a boolean Attribute from another class

Hybrid View

  1. #1
    Expensive Sushi
    Join Date
    Oct 2012
    Posts
    9

    Calling a boolean Attribute from another class

    Code:
    public class validateLogin{
     
       
        public boolean validate(String username, String password) {
            
            boolean state = false; 
           
           
                   if(username.equals(user) && password.equals(pass))
                  {                  
                      state = true;
                  }
                  else
                      state =false;         
                }           
                
            
            }
            return state;    
            
            
        }
    Then I create a page where the username and the password are going through and the above class is just validate. If the state is true the user will be redirected to another page; however, I don't know how to call the state attribute and put it in an if statements. I create an object and call the validate method know I want to create and if statement .
    ValidateLogin v = new ValidateLogin();
    v.validate(username, password);
    if(state = true) //HOW DO I CALL THIS ATTRIBUTE THAT IS IN ANOTHER CLASS?
    redirect to page

  2. #2
    I had the same problem. In order to modify variables from different classes, I made them extend the class they were to modify. I also made the super class's variables static so they can be changed by anything that inherits them. I also made them protected for more flexibility.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •