Java   View all facts   Glossary   Help
syntactic unit > access unit > constructor
Next access unitinterface    Upaccess unit    Previous access unitclass   

constructor
subjectfact 
constructoralways have the same name as the classadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:32.0
can be overloaded using method name overloadingadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:32.0
can call another constructor in the same class, instead of the superclass's zero-parameter constructor, by adding a new statement (as the first statement in the constructor) consisting of the keyword this followed by an argument listadded by: JK, source: On To Java, 2001-10-19 11:36:32.0
can call another constructor in the superclass, instead of the superclass's zero-parameter constructor, by adding a new statement (as the first statement in the constructor) consisting of the keyword super followed by an argument listadded by: JK, source: On To Java, 2001-10-19 11:36:32.0
can not be called directlyadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:32.0
can not return a valueadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:32.0
can use a constructor of the class's superclass with a super() calladded by: DS, 2001-10-19 11:36:32.0
has definition A procedure that is called whenever a new object is created    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:32.0
does not have a return typeadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:32.0
does not have a return type since it does not return a valueadded by: JK, source: On To Java, 2001-10-19 11:36:32.0
does not return a valueadded by: JK, source: On To Java, 2001-10-19 11:36:32.0
facilitates data abstractionadded by: JK, source: On To Java, 2001-10-19 11:36:32.0
has the same name as its classadded by: JK, source: Sun Java Tutorial, 2001-10-19 11:36:32.0
has example
// Example of creation of an account with an initial balance
public Account(String accountHolder, float initialBalance)
{
this.accountHolder = accountHolder;
balance = initialBalance;
opened = new Date();
}
//Example of creation of an account with no initial balance
public Account(String accountHolder)
{
this.accountHolder = accountHolder;
balance =0.0;
opened = new Date();
}   
source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:32.0
has example
//Example of constructor for the class Stack
public Stack() {
items = new Vector(10);
}
added by: JK, source: Sun Java Tutorial, 2001-10-19 11:36:32.0
has purpose to initialize the instance variables of a newly created object and perform any other needed initialization    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:32.0
has typically 1 or more arguments that determine some of the values of the variables of the classadded by: DS, source: Sun Java Tutorial, 2001-10-19 11:36:32.0
is not a memberadded by: JK, source: Sun Java Tutorial, 2001-10-19 11:36:32.0
is not a methodadded by: DS, source: Sun Java Tutorial, 2001-10-19 11:36:33.0
is a subtopic of Constructors2001-10-19 11:36:33.0
is called when the new operator is used to create an instance of a classadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:33.0
is not inherited by a subclassadded by: JK, source: Sun Java Tutorial, 2001-10-19 11:36:33.0
is part of class    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:33.0
is a kind of access unit2001-10-19 11:36:33.0
may have access modifier added by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:33.0
normally calls the zero-parameter constructor in the direct superclass firstadded by: JK, source: On To Java, 2001-10-19 11:36:33.0
provides a way to initialize a new objectadded by: DS, source: Sun Java Tutorial, 2001-10-19 11:36:33.0
access unithas access mode2001-10-19 11:35:59.0
syntactic unithas syntax rule
bold = mandatory
italic = non-terminal
normal font = optional
2001-10-19 11:38:04.0

Kinds of constructor :

Next access unitinterface    Upaccess unit    Previous access unitclass