File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Abstract Methods Vs. Static Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract Methods Vs. Static Methods" Watch "Abstract Methods Vs. Static Methods" New topic
Author

Abstract Methods Vs. Static Methods

Kalyan Naveenan
Greenhorn

Joined: Jul 23, 2011
Posts: 12
Hello everyone, can anyone here help me understand the difference between an abstract method and a static methods. As i understand in both these type of methods an object instantiation is not allowed. So why use two terms for the same function.
Walter Gabrielsen Iii
Ranch Hand

Joined: Apr 09, 2011
Posts: 158
A static method is outside the flow of objects. You don't need an object to call a static method. You call a static method with the class name, .(dot), and method name, example: Math.random().

An abstract method is empty, like an interface. You must create a subclass and override the method to make it work.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

For abstract methods, you will need to instantiate an object. Just not an object of that class, but of some class that extends the class and implements the method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40041
    
  28
The Campbell Ritchie classification of methods classifies them into 8 categories. Every method falls in 4 categories, giving 16 different combinations, 1357, 1358, 1367, 1368, 1457, 1458, 1467, 1468, 2357, 2358, 2367, 2368, 2457, 2458, 2467, 2468
  • 1: Those which require information from the outside world to operate. You can recognise these because they have method parameters.
  • 2: Those which do not require information from outside; they have empty () in their heading.
  • 3: Those which send (back) information to outside. They have a return type.
  • 4: Those which do not send information (back); they have void instead of a return type.
  • 5: Those which require, seek, inspect or use information from inside their own object.
  • 6: Those which do not require any information from inside their own object.
  • 7: Those which alter, insert or modify information inside their own object.
  • 8: Those which do not modify insert or alter any information inside their own object.

  • You can add a category 1½ for methods which take an "output parameter".

    Now, if you have a method which falls both into category 6 and category 8, it doesn't do anything with an object or instance. So why does it need an object or instance? Why not label it static? My idea of a static method is one which takes no information from its object and sends no information to its object. So you associate it with a class rather than an object.
    The Java™ definition of an abstract method is that it is an instance method, ie it falls in category 5 or category 7 or both, doing something with information inside its own object. But the form it is given in is incomplete and different classes must implement it differently.
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19783
        
      20

    Campbell Ritchie wrote:Now, if you have a method which falls both into category 6 and category 8, it doesn't do anything with an object or instance. So why does it need an object or instance? Why not label it static? My idea of a static method is one which takes no information from its object and sends no information to its object. So you associate it with a class rather than an object.

    Unless you implement the method because the class implements an interface. Often the implementing class becomes a singleton. A good example is String.CASE_INSENSITIVE_ORDER. The class is an unknown class that implements java.util.Comparator. Because the method is defined by an interface it cannot become static. Instead, there is only one instance of the implementing class.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Abstract Methods Vs. Static Methods