HOME

TheInfoList



OR:

In
computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
, a nullary constructor is a
constructor Constructor may refer to: Science and technology * Constructor (object-oriented programming), object-organizing method * Constructors (Formula One), person or group who builds the chassis of a car in auto racing, especially Formula One * Construc ...
that takes no
argument An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialect ...
s. Also known as a 0-argument constructor, no-argument constructors or default constructor.


Object-oriented constructors

In
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
, a
constructor Constructor may refer to: Science and technology * Constructor (object-oriented programming), object-organizing method * Constructors (Formula One), person or group who builds the chassis of a car in auto racing, especially Formula One * Construc ...
is code that is run when an object is created.
Default constructor In computer programming languages, the term default constructor can refer to a constructor that is automatically generated by the compiler in the absence of any programmer-defined constructors (e.g. in Java), and is usually a nullary constructor. I ...
s of objects are usually nullary.


Java example

public class Example


Algebraic data types

In algebraic data types, a constructor is one of many tags that wrap data. If a constructor does not take any data arguments, it is nullary.


Haskell example

-- nullary type constructor with two nullary data constructors data Bool = False , True -- non-nullary type constructor with one non-nullary data constructor data Point a = Point a a -- non-nullary type constructor with... data Maybe a = Nothing -- ...nullary data constructor , Just a -- ...unary data constructor


References

Method (computer programming) Articles with example Haskell code Articles with example Java code {{Comp-sci-stub