Sponsored Links

Interview Questions



INTERVIEW QUESTIONS J2EE JAVA DETAILS

Question: Why we have used to in main method in JAVA this words
1)public
2)static
3)void
4)main
5)(String args[])

Answer: The "public" keyword is an access specifier,which allows the programmer to control the visibility of class members.
When a class member is preceded by "public",then that member may be accessed by code outside the class in which it is declared.
In this case,main() must be declared as "public",since it must be called by code outside of its class when the program is started.
The keyword "static" allows main() to be called without having to instantiate a particular instance of class.
This is necessary since main() is called by the JVM before any object are made.The keyword "void" simply tells the that main() doesnot return a value .As we will see, methods may also return values.
"String args[]" declares a parameter named "args", which is an array of instance of the class "String".(Arrays are collections of similar objects).
Objects of type "String" store character strings. In this case, "args" receives any command -line arguments present when the program is executed.

Category Java Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.3) By 7363 users
Added on 12/11/2012
Views 70877
Rate it!

Question: Why we have used to in main method in JAVA this words
1)public
2)static
3)void
4)main
5)(String args[])


Answer:

The "public" keyword is an access specifier,which allows the programmer to control the visibility of class members.
When a class member is preceded by "public",then that member may be accessed by code outside the class in which it is declared.
In this case,main() must be declared as "public",since it must be called by code outside of its class when the program is started.
The keyword "static" allows main() to be called without having to instantiate a particular instance of class.
This is necessary since main() is called by the JVM before any object are made.The keyword "void" simply tells the that main() doesnot return a value .As we will see, methods may also return values.
"String args[]" declares a parameter named "args", which is an array of instance of the class "String".(Arrays are collections of similar objects).
Objects of type "String" store character strings. In this case, "args" receives any command -line arguments present when the program is executed. Source: CoolInterview.com

Answered by: Purella Satyanarayana | Date: 1/30/2008 | Contact Purella Satyanarayana Contact Purella Satyanarayana

public means common for all classes.
static means common for all objects.
void means it did nt return any thing.
Strung args[] is for what ever we enter through command line argument that will be collected in one arry i.e args[]. Source: CoolInterview.com

Answered by: sunitha | Date: 2/6/2008 | Contact sunitha Contact sunitha

This uses public so that it is visible every where
This is static so that to call this function we don't need to create the object of that class its belong to.
It uses void to maintain a standard, because if we write int or char or anything else then it wont be proper function overloading.
We use String arg[] to get any no. of argument that we want from the user,If we give different arguments then it means that we are overloading, to avoid it we have a standard. Source: CoolInterview.com

Answered by: shweta | Date: 2/7/2008 | Contact shweta Contact shweta

In main method each word have specific meaning like we declare main method as public so that JVM will able to execute it(i.e. method will accessible outside the class in which it is declared).We declare it as static so that JVM will able to execute it without creating object of that class .we declare void to inform that main method doesn't return any value & args[] is array of type String which is called as command line argument & we can pass value at runtime to main method.
Source: CoolInterview.com

Answered by: Rahul pande | Date: 2/12/2008 | Contact Rahul pande Contact Rahul pande

PUBLIC is used so that main can be accessed out of the class.

STATIC keyword is used so that main can be accessed without creating object of the class in which main is declared
VOID is used because main is also a function and function should have return type
MAIN-main is function from where our function starts and from main all other function are called
String args[]-is used for the command line argument and is part of syntax of main,also String is a class in which any type of data type can be accepted. Source: CoolInterview.com

Answered by: krishna | Date: 2/20/2008 | Contact krishna Contact krishna

public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.
static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.
void: main does not return anything so the return type must be void.
The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line. Source: CoolInterview.com

Answered by: reddy | Date: 2/24/2008 | Contact reddy Contact reddy

"public" means main method available any where inside or outside of the class.
"static" it means that without using an object main method will be executed.
"void" it means main method doesn't return any value.

string(args) it means it accepts data from outside into the method.It is string type arguments thier value passed to main method Source: CoolInterview.com

Answered by: sandeep | Date: 3/12/2008 | Contact sandeep Contact sandeep

public is for access modifier.
void is return type.
String args[] is String type arguments. Source: CoolInterview.com

Answered by: rusho | Date: 4/26/2008 | Contact rusho Contact rusho

static=because it can be call by without creating object of class
public=can be accessed from anywhere
void= return nothing
main= to tell that it is entry point of program.

i think now you get your answer Source: CoolInterview.com

Answered by: Pankaj Goswami | Date: 4/28/2008 | Contact Pankaj Goswami Contact Pankaj Goswami

public is a access specifier which allows the programmer to control the visibility of class members.

we use static keyword because the main function is called before initialisation any object.To do this the main function is declared as static

The main function doesnot return any value.so,it is declared as void

string args declares a parameter named args
args receives any command line arguments present in the program Source: CoolInterview.com

Answered by: mahi | Date: 8/29/2008 | Contact mahi Contact mahi


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
Addition of two numbers using Bitwise operators.
Reading An 2D array using single for loop
View Answer
What is UML patterns?give me clear explanation
View Answer
While developing one in JSP page we are sending request to Struts frame work.If we click two times submit button then First time only it should accept request and second time should reject that request in struts frame work.

How we can do that in controller itself...I am waiting for your Response...

View Answer
Can I execute or call one applet from another applet? If so then how??? Please Reply me...
Thanks
View Answer
what is method declaration,method attributes,method modifiers and parameters
View Answer
System Class is Used to Output text onto the Screen?
it True or False
View Answer
what is the first statement in construtor?
View Answer
What is the abstraction? Give example?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Java Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2025 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions