Sponsored Links


Results 1 to 2 of 2

Thread: what is the difference between Static method and the method we write in Clas

  1. #1
    Senior Member saneha's Avatar
    Join Date
    Apr 2011
    Posts
    266

    Icon51 what is the difference between Static method and the method we write in Clas

    Sponsored Links1


    What is the difference between Static method and the method we write in Class definition?

    Sponsored Links

    Why Static method can not be called using Object of a class?

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    The instance variables and methods belong to an object of a class whereas static data members and methods are associated with class and are not tied to any object. There will be only single copy of static data member inside a class. The static data members are shared by all the objects of class. The static methods can not only be accessed by class but by the objects of a class. The non-staic variable and methods cannot be accessed within static method.

    // See the example below

    class Employee{
    private static int count = 0; //staic variable

    public Employee(){
    count++ ;
    }

    // static method
    public static void get()
    {
    System.out.println("The value of count: " + count);
    }

    } // end of Employee class

    // driver class
    public class Example {

    public static void main(String[] args){

    Employee.get(); // calling static method using class

    Employee e1 = new Employee();
    e1.get() ; // calling static method using an object of class

    Employee e2 = new Employee();
    e2.get() ; // calling static method using an object of class

    } // end of main

    } // end of class

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mobilink my status activation method
    By Xpert in forum Mobilink Jazz
    Replies: 0
    Last Post: 08-19-2013, 07:51 PM
  2. the method of balancing an anl tree?
    By Vuhelper in forum C++ Programing
    Replies: 0
    Last Post: 01-04-2012, 10:30 PM
  3. Replies: 0
    Last Post: 07-17-2011, 05:08 PM
  4. flush method in java 2011
    By saneha in forum Java forum
    Replies: 1
    Last Post: 04-24-2011, 09:49 PM
  5. Jacobis method
    By Vuhelper in forum Get Solution In 24 Hour
    Replies: 2
    Last Post: 04-24-2011, 04:12 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
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft | Jobs