This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
There are classes that cannot be instantiated, but all the methods are static, like java.lang.System and java.lang.Math. These aren't abstract, but have private, unused constructors. One reasonable use of a static method in an abstract class would be a factory methods. You would call Foo.createNew(arguments) to create an instance of some concrete subclass.
1. An abstract class is a class that is incomplete, or to be considered incomplete. Classes C1 and C2 implement the methods of I. 2. A method declared in an interface must not be declared static. The static methods common to all subclasses of A are declared in A. [ October 10, 2003: Message edited by: Marlene Miller ]
Originally posted by Marlene Miller: An abstract class is a class that is incomplete, or to be considered incomplete.
Abstract is an inheritance hierarchy tool. It allows you to create classes that you don't want to be instantiated but you do want to use as models for child classes. Abstract classes do not have to have abstract methods. This is a perfectly valid abstract class:
In addition to the previous posts, I offer two other thoughts. First, it is perfectly normal and valid for an abstract class to contain non-abstract (i.e., fully implemented) methods, static or otherwise. An abstract class can include as much implementation as is appropriate. This is one thing that differentiates an abstract class from an interface. Second, defining a static method inside an abstract class enables that method to be called independently of any object. Thus, a static method of an abstract class can be called without there being any instances of a concrete subclass in existence. Here is a rather contrived example that illustrates these two points.
The output is shown here. Number of objects that include A: 0 Number of objects that include A: 1 Number of objects that include A: 2 [ October 10, 2003: Message edited by: Herb Schildt ]
For my latest books on Java, including my Java Programming Cookbook, see HerbSchildt.com