• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About abstract class

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Saurabh Verma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnak you Burkhard Hassel....
 
reply
    Bookmark Topic Watch Topic
  • New Topic