Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is the difference between Static method and the method we write in Clas
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
What is the difference between Static method and the method we write in Class definition?

Why Static method can not be called using Object of a class?
Reply
#2
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

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between Heap and Stack memory saneha 3 4,827 04-01-2015, 03:36 PM
Last Post: Xpert
  Difference between java netbeans and tomcat 6.0 Xpert 0 2,244 06-23-2011, 11:38 PM
Last Post: Xpert
  How static class variables get initialized Vuhelper 0 855 06-09-2011, 09:56 PM
Last Post: Vuhelper
  Difference between Java and Netbeans 2011 Xpert 0 3,067 05-11-2011, 04:59 PM
Last Post: Xpert
  Why getCountStudent() method is called using Class Name instead of first making new saneha 1 5,919 04-28-2011, 09:10 PM
Last Post: Vuhelper
  what is the difference between Java and Java 2EE saneha 1 2,089 04-28-2011, 08:50 PM
Last Post: Vuhelper
  Java is to Write Once Run Anywhere thats what java language Xpert 0 2,018 04-28-2011, 04:14 AM
Last Post: Xpert
  Differentiate between static and nonstatic members in java 2011 saneha 1 2,476 04-27-2011, 11:03 PM
Last Post: Vuhelper
  whats the difference in node stream and filter stream? saneha 1 2,780 04-27-2011, 11:00 PM
Last Post: Vuhelper
  What is the difference between Java and Java 2EE saneha 1 1,953 04-27-2011, 06:25 AM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 2 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support