• 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

Abstract class's constructor.

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am sure that we can create constructors in an abstract class. But, Why it should have constructor because it is not concrete class. What purpose it would solve ?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would solve the same purpose as for any other class, namely to initialize an instance of the class. This would include initializing any instance variables, for example. Go back and review your study notes on constructors to see what they do.
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing is that suppose you extend an abstract class and some concrete class extends that abstract class
so when we are calling the concrete class constructor, it will call its superclass constructor as per the rule
and hence it is mandatory for any class to have constructor


happy to help
 
Raja Narasimha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Prasad. This makes sense.

Prasad Kharkar wrote:Another thing is that suppose you extend an abstract class and some concrete class extends that abstract class
so when we are calling the concrete class constructor, it will call its superclass constructor as per the rule
and hence it is mandatory for any class to have constructor


happy to help

 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Java compiler itself gives no-arg constructor for each class when there is no other flavor of constructors... We dont have to add any constructors for the abstract class...
reply
    Bookmark Topic Watch Topic
  • New Topic