1. Q) What is the requirement to provide String data type as parameter to the main()( method ?
Ans):-
From developers to developer the type of command line input is varied. Even through developers are providing variable types of command line input our main() method parameter must store all the types of command line input. To active this requirement, main() method must required a data type, it able representing any type of data. In JAVA/J2EE technologies only string data type is having the capability to represent any type of data, so that, main() method must required string data type as parameter.
2. Q) What the requirement to provide array as parameter to main() method?
Ans):-
From developer to developer, number of command line input are varied. Even through developers are providing variable number of command line input. Main() pararmeter must store all variable number of command line input.
In java/J2EE technologies, array types are able to store more then one value, so that, main() method must have array type as parameter.
Note:-
If we declare main() method without String[] parameter then compiler will not rise any error, but JVM will providing the following.
JAVA6: java.lang.NoSuchMethodError:main
JAVA7: Error: main method not found in class Test, please define the main method as
public static void main(String[] args)
3. Q) Find the void Syntax of main() method from the following list?
Ans):-
public static void main(String[] args) --->Valid
public static void main(String []args)--->Valid
public static void main(String args[]) --->Valid
public static void main(String... args)--->Valid
static public void main(String[] args) --->Valid
public static final void main(String[] args) --->Valid
final public static void main(String[] args)--->Valid
final strictfp public static void main(String[] args) --->Valid
public void main(String[] args) --->Invalid
static void main(String[] args) --->Invalid
public void static main(String[] args) --->Invalid
abstract public static void main(String[] args) --->Invalid
No comments:
Post a Comment