1.) if we use "private" in place of "public" in public
static void main()...
2.) if we use "int" in place of "void"....
3.) can we ommit "static" keyword from that statement....
4.) also can we give the command line arguments type as int
type or float,etc.(.i.e (string args[]))
Answer / ankur pandya
Hello.
the sign for main method in Java is
public static void main(String arg[])
or
public static void main(String[] arg)
Because, "public" modifier says this method is accessible
from out side the class, "static" says that this is not
instance method. Means method is of class and not of any
object of class. "void" means this method does not returns
any thing.
and "String[] arg" says the method take the argument of type
Sting Array, so that we can supply argument of any type (and
cast it later on) and in any quantity. String is only option
to do so in Java ;) .
Now
1. if we use "private" in place of "public" than compiler
will not generate any error. But while running this program
we get "Main method not public". Hence Main method become
unreachable.
2. if we use "int" in place of "void", then compile will not
generate any error but run time error saying
"java.lang.NoSuchMethodError: main" because we can not
overload "main" method.
3. if we omit "static" keyword then same runtime error
"java.lang.NoSuchMethodError: main" will display, because we
can not override "main" method. If it is not "static" then
all of its object can override its definition, which is not
good for a program.
4. if we give the command line arguments type as int
type or float,etc.then same runtime error
"java.lang.NoSuchMethodError: main" will display, because we
can not overload "main" method. The program should have only
one beginning of a program. If you want to supply any int or
float then you'll have to use type casting. Usually we do
not supply any argument, in this case compiler will
understand arg[] = null.
Is This Answer Correct ? | 16 Yes | 3 No |
Write an algorithm program in java for the following question.. In a VLSI design techniques,they used rectangles to design circuits. EVery rectangle is to be placed according to x,y coordinates. Check whether or not two rectangles overlap each other. Here overlapping of rectangles is acceptable, if 1) one rectangle intersect with other. 2) one rectangle fully covers other. The time of algorithm should not exceed o(n logn).
Why should we create an object? what is a need of it? Apart from access members of a class i want what is a need of object what does it contain?? In normal class to access any member of thaht class we create object where as for static class we access its members using class name. what is a difference between them... thanks in advance.
In Java why we write public static void main(String args[]) why not main()?
46 Answers Aptech, GE Healthcare, Infosys, Microsoft, New Horizon, Practical Viva Questions, TCS, Wipro,
Can I use % with real numbers?
can we have function for truncating the sign as like abs in oracle.
what are three ways in which a thread can enter the waiting state? : Java thread
Can we serialize singleton class?
Explain what are final variable in java?
What is function overriding and overloading in java?
What is numel matlab?
What is the major advantage of external iteration over internal iteration?
Explain tree set and its features?