Nullary Constructor
   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 ana ...
, a nullary constructor is a constructor 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 dialectic ...
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 pr ...
, a constructor is code that is run when an
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ...
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 In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types. Two common classes of algebraic types are product types (i.e., ...
, 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