Can we interchange the modifiers used with main() method?
class MainMethod2
{
static void public main(String[] args)
{
System.out.println("Can we interchange the modifiers?");
}
}
/*
Output:- Compilation error
Explanation:- Yes we can interchange modifiers of main method but cannot interchange return type.
There are 11 modifiers in which we can use 5(public,static,final,synchronized,strictfp)
modifiers with main() method. Excpet these if we are trying to use other modifier then we will get compilation error. We can write like this:-
static public void main(String[] args)
static final public synchronized strictfp void main(String[] args)
*/
{
static void public main(String[] args)
{
System.out.println("Can we interchange the modifiers?");
}
}
/*
Output:- Compilation error
Explanation:- Yes we can interchange modifiers of main method but cannot interchange return type.
There are 11 modifiers in which we can use 5(public,static,final,synchronized,strictfp)
modifiers with main() method. Excpet these if we are trying to use other modifier then we will get compilation error. We can write like this:-
static public void main(String[] args)
static final public synchronized strictfp void main(String[] args)
*/
0 comments: