Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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[]))



1.) if we use "private" in place of "public" in public static void main()... ..

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

Post New Answer

More Core Java Interview Questions

What is the difference between replace and replace all?

0 Answers  


What is maximum size of arraylist in java?

0 Answers  


Explain the concept of hashtables?

0 Answers  


I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?

0 Answers  


What is the difference between quicksort & mergesort? When should they be used? What is their running time?

0 Answers   Akamai Technologies,


what are the diffrences between interface and abstract class?

4 Answers  


what are ER diagrams?

2 Answers  


Does the order of public and static declaration matter in main method?

0 Answers  


Why string is not a wrapper class?

0 Answers  


Explain the difference between intermediate and terminal operations in java8?

0 Answers  


Difference between comparator and comparable in java?

0 Answers  


Which is dependent variable?

0 Answers  


Categories