Is this a valid java program?
class MainMethod1
{
}
/*
Output:- No compilation error
Explanation:- Yes, it is valid Java Program.Whether the class contains main() method or not and
whether main() method is properly declared or not. Thses things won't be checked by
compiler. At runtime JVM is responsible to check these things. At runtime if JVM is
unable to find required main() method then we will get Runtime Exception saying
"NoSuchMethodError:main" on jdk 1.6 version. If we are using jdk 1.7 or greater
version then we will get Runtime Error saying "Main method not found in class
MainMethod1, please define the main method as:
public static void main(String[] args)"
*/
{
}
/*
Output:- No compilation error
Explanation:- Yes, it is valid Java Program.Whether the class contains main() method or not and
whether main() method is properly declared or not. Thses things won't be checked by
compiler. At runtime JVM is responsible to check these things. At runtime if JVM is
unable to find required main() method then we will get Runtime Exception saying
"NoSuchMethodError:main" on jdk 1.6 version. If we are using jdk 1.7 or greater
version then we will get Runtime Error saying "Main method not found in class
MainMethod1, please define the main method as:
public static void main(String[] args)"
*/
0 comments: