• 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 constructors

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can an abstract class have constructors?

I would have thought no , as they cannot be instantiated , so there is no real purpose... Am I right?
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, an abstract class can have constructors.
An abstract class may have instance variables and non-abstract methods (common to all concrete subclasses) that operate on those variables. A constructor could be used to initialize the instance variables.
A constructor of a concrete subclass would invoke the superclass constructor to initialize the variables of the abstract superclass.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Graph is part of a framework. It supplies nearly all of the methods to support a generic graph editor.
SimpleGraph is a client-defined extension that supplies the geometric shapes of the nodes and edges to be used in the graph.

Graph is an abstract class. It needs a constructor to initialize the variables to do its work.

(From Cay Horstmann�s Object Oriented Design & Patterns)
[ May 27, 2003: Message edited by: Marlene Miller ]
reply
    Bookmark Topic Watch Topic
  • New Topic