Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - Finding the output (Q.No. 3)
3.
public class F0091
{
public void main( String[] args )
{
System.out.println( "Hello" + args[0] );
}
}
What will be the output of the program, if this code is executed with the command line:
> java F0091 world
Answer: Option
Explanation:
Option D is correct. A runtime error will occur owning to the main method of the code fragment not being declared static:
Exception in thread "main" java.lang.NoSuchMethodError: main
The Java Language Specification clearly states: "The main method must be declared public, static, and void. It must accept a single argument that is an array of strings."
Discussion:
18 comments Page 2 of 2.
Balaji said:
10 years ago
If we add static on main method then also getting same result. Please guide me.
Artspade said:
8 years ago
using public static void main(String[] args) { s.o}
The result is world.
The result is world.
Rupa said:
1 decade ago
It is declared as static then o/p is Helloworld.
Jyothirmai said:
1 decade ago
Why should we use static in before main method?
Shiwam said:
1 decade ago
If it is declared as static then o/p is ?
Sathish kumar said:
5 years ago
@Teja.
Kindly, explain your answer.
Kindly, explain your answer.
Teja said:
6 years ago
The output will be Hello World.
Riya said:
8 years ago
Why it is run time exception?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers