Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi how i can induce qwe() method in main class?

What I have tried:

public class czas {
 
    public static void main(String[] av) {
       
 
        
    }
    public String qwe(){
    SimpleDateFormat a = new SimpleDateFormat("EEE MMM d kk:mm:ss");
        
        String time=a.format(new Date());
        return time;
    }
}
Posted
Updated 12-Jan-17 6:44am

1 solution

You cannot execute qwe function in the main function, (I assume that is your problem), the reason for that is that your main function is static, whereas your qwe function is instance function. To do so, either change the signature of your function to,
public static String qwe(){

Or create a new instance of your czas class and then call that function, like,
public class czas { 
    public static void main(String[] av) {
        System.out.println(new czas().qwe()); 
    }

    public String qwe(){
        SimpleDateFormat a = new SimpleDateFormat("EEE MMM d kk:mm:ss");    
        String time=a.format(new Date());
        return time;
    }
}

This would work and will give you the result. You need to understand the difference in static and instance function — which many beginners do not know, so I won't blame you here.
 
Share this answer
 
Comments
Ra Fau 12-Jan-17 12:50pm    
thx for help
Afzaal Ahmad Zeeshan 12-Jan-17 13:07pm    
If that works, also mark the post as a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900