Cannot access method in other project of java

I have create one java project which has following class with it's body.

package tfimvalidation;

public class ValidateToken {
    public void display()
    {
        System.out.println("Yor package imprort succesfully");
    }
}

This is java project now I have create jar file of this project and add it in other my dynamic web project.

There is I can access ValidateToken class and package with following statement

ValidateToken validateToken = new ValidateToken();

but I cannot access validateToken.display();

it's give this type of error; Syntax error on token "display", Identifier expected after this token.

This is code of second project where I have use jar of first project. import tfimvalidation.ValidateToken;

public class Main
{
     ValidateToken validateToken=new ValidateToken();
    validateToken.display(); //Here gives above shown error.
}   
Jon Skeet
people
quotationmark

You can't just call a method in a class declaration like that. You can declare fields in a class declaration, but method calls (other than those used for field initializers) have to be in methods or constructors. For example:

import tfimvalidation.ValidateToken;

public class Test {
    public static void main(String[] args) {
        ValidateToken token = new ValidateToken();
       token.display();
    }
}

people

See more on this question at Stackoverflow