Results 1 to 2 of 2

Thread: Static Methods

  1. #1
    pardhu is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Question Static Methods

    HI friends , I have a doubt regarding static methods.
    we know that static methods can only call other static methods.
    main() is a static method and it calls instance(non-static) methods of a class with the help of an object.
    why is it so ?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Static Methods

    The static methods can only call other static methods in the same class. When the static methods are not in the same class then you have to access it through their classes. This is also true for instance methods. To access it you have to create an instance of those classes, or what you call as with the help of an object.

    The main() method belong to the current class, when it need to access other class methods then it has to create an instance of those classes. If no instance available then there is no way for the main() method to work with other objects.

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Replies: 1
    Last Post: 10-23-2011, 12:37 PM
  3. Static and non static class methods question
    By silverglade in forum New To Java
    Replies: 2
    Last Post: 05-14-2011, 10:10 PM
  4. Recursion with static and non static methods
    By sh4dyPT in forum New To Java
    Replies: 14
    Last Post: 03-27-2009, 06:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •