aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract class 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract class" Watch "abstract class" New topic
Author

abstract class

chetna_jain
Greenhorn

Joined: Aug 25, 2001
Posts: 28
i have the doubt can abstract class have main method.
acc. to me as it cannot be insatinated it cannot have main method
thanx in advance
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
Abstract classes can have main method. Main methods have nothing to do with instantiation. Main method is used for executing your class.It is the entry point to your program.
The following abstract method has a main method which when executed outputs Hello.
Hope this helps
Roopa.
public abstract class Abs
{
public static void main(String [] args)
{
System.out.println("Hello");
}
abstract void methodA();

}
Originally posted by chetna_jain:
i have the doubt can abstract class have main method.
acc. to me as it cannot be insatinated it cannot have main method
thanx in advance

chetna_jain
Greenhorn

Joined: Aug 25, 2001
Posts: 28
Thanks a lot roop i got my doubt cleared
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Besides,
main is static method and belongs to the class and not to an instance, no reason why it can't be in a an abstarct class. Moreover, you can have any other (user defined) static method in an abstract class, which can be invoked w/o creating an instance of a class.
HTH,
- Manish
Hassan Naqvi
Ranch Hand

Joined: May 03, 2001
Posts: 158
Good addition Manish.


Always Belive On Logic!!
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Abstract class can even have a constructor
Ex: java.awt.Component
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
When a class is declared 'abstract' it just means that not all of its methods are implemented. It can't be instantiated because it's not complete.
The 'abstract' tells you that if you want to use the class, you'll first need to subclass it and implement any abstract methods.
It may be a complete class with just one non-implemented method! Which means it can have full methods, ctors, and a main().
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

[This message has been edited by Jane Griscti (edited October 02, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract class