Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About abstract class" Watch "About abstract class" New topic
Author

About abstract class

Saurabh Verma
Ranch Hand

Joined: Aug 13, 2007
Posts: 38
Hi,

I have two confusion about abstract class

1>Can we create a constructor for an abstract class?

2>If yes,what is the use of that.

Thnaks.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Yes you can. And if you don't the compiler will provide the invisible default constructor for your abstract class.

The use: Remember, when you extend a class (also true for an abstract class) every constructor in that subclass that does not call another constructor of the same class will call
super();
or perhaps super(with_an_argument).

So the use of constructors in abstract classes is just the same as for any concrete class. To perform things that should be done when a new object is created.
Easiest example is the initialization of variables with some propper values.

Example:


all events occur in real time
Saurabh Verma
Ranch Hand

Joined: Aug 13, 2007
Posts: 38
Thnak you Burkhard Hassel....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: About abstract class
 
Similar Threads
Method Overriding
inheritance
abstract class
Why generic servlet is an abstract class?
abstract vs interface