Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do we have to declare main method always public!If this ques. comes in the exam what should be written true or false.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although it will compile and run without being public (an error in the JDK that will not be addressed) it is supposed to be public. The exam might ask something like what the standard signature of the main method must be (according to the books and mocks - I haven't tested yet).
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To a question which reads:
Do we have to declare main method always public?
My Answer would be FALSE.
Also, I am by the fact that I could actually
run an application with a "private" main() method.
The following code runs and the output is:
Byte value is = 10

My understanding was that I will get an error
saying "main() method not found" or something
like that.
Am I missing something ?
Oh, wait! My copy of the JDK is missing
something ?
Thanks.
- satya

[This message has been edited by satya5 (edited May 05, 2000).]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satya,
I too was in the same boat a few weeks ago and
got very very very
For the sake of the certification exam, it
is safe to assume the signature of the main
method is
<PRE>
public static void main ( String[] args ).
</PRE>
It is the gospel.
However, in reality it can have private or no
access specifier and it still works. It has
already been logged with SUN, and they have no
plans of fixing it. They don't think it is a
bug.
Hope it clears your confusion ( or does it
make you ??)

Ajith

[This message has been edited by Ajith Kallambella (edited May 05, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks.
You see, I had a hunch for that..."my copy of
JDK is missing something". Its not me missing
all the time you know.
Regds.
- satya
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh no all this is a big :confused what should we select if we get such a question in the exam?
 
kking
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a generic question is asked concerning the construction of the main method (as in a fill in the blank question) you type:
public static void main(String [] args);
you may not have to type in the parameter list. In that case type...
public static void main.

[This message has been edited by kking (edited May 05, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

unregistered:
I thought I answered the question asked by Sim.
Check my previous post above.
I would go with FALSE, if this was a TRUE/FALSE qutn.
If it was a fill in the blank, I would go with what
the KING says.
Regds.
- satya
 
Simran Thakur
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks friends for clearing my doubt.
sim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic