• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Signature of the main method

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1)Can any one expline the impartence of keywords in main method like public,void,static?
2)Can we override the main method?
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

)Can any one expline the impartence of keywords in main method like public,void,static?



public means you can access that method from anywhere(means from outside package).
void means it does not return anything.
static means there no instance variables of any object of the class they are defined in. main method is entry point of any program in java. To invok instance method we required object but at starting there is no any object so main method is static.

Can we override the main method?



Yes you can , by supplying different argument list.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pramod P Deore wrote:

Can we override the main method?


Yes you can , by supplying different argument list.


That's not overriding - it's overloading. And you can't override a static method anyway.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Venu Babu Ravi wrote:
1)Can any one expline the impartence of keywords in main method like public,void,static?
2)Can we override the main method?



Hi we can override a mail method..........see below........




but i am wondering how it is possible......how can we overide main because main is static method...........and static method cannot be overridden............can anybody explain this......
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That's not overriding - it's overloading. And you can't override a static method anyway.



Oh I am so sorry, I thought Venu is talking about method overloading. Thanks Matthew Brown for correcting me
 
Venu Babu Ravi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pramod,

my intention is , if we change those keywords can JVM will able to create object for class?
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is fixed that you have to use main method signature as public static void main(String[] args){ }
But you can also create object outside main method (inside another method).

 
Venu Babu Ravi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for all of you for sharing this information.
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@phil

yes absolutely we can define main method again in subclass but it is not called as overriding (as it is a static method )
this is called as method hiding


now in your program we have written two main methods
now you may be wondering from where the execution starts in the program

the execution of the program will start from the main method of the class which we launch using java command
see the following output for your program


Always remember that static methods can be overridden but it is not called as overriding it is called as method hiding and we call those methods using class names

hope this is clear now
happy coding
hth
 
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad wrote

the execution of the program will start from the main method of the class which we launch using java command




super explanation about the start of execution of program
thanks Prasad .
 
reply
    Bookmark Topic Watch Topic
  • New Topic