Java   View all facts   Glossary   Help
syntactic unit > access unit > constructor > default constructor
Next constructorconstructor with no parameters    Upconstructor

default constructor
subjectfact 
default constructorhas definition A constructor that is automatically provided by the runtime system for any class that contains no explicit constructorsadded by: JK, source: Sun Java Tutorial, modified by: WH, comment: Distinguished explicit constructors from default constructors, reference: Source 2, 2001-10-19 11:36:36.0
has no parametersadded by: JK, source: On To Java, 2001-10-19 11:36:36.0
is a subtopic of Constructors2001-10-19 11:36:36.0
is a kind of constructoradded by: JK, 2001-10-19 11:36:36.0
constructorcan be overloaded using method name overloading2001-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 list2001-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 list2001-10-19 11:36:32.0
can not be called directly2001-10-19 11:36:32.0
can not return a value2001-10-19 11:36:32.0
can use a constructor of the class's superclass with a super() call2001-10-19 11:36:32.0
does not return a value2001-10-19 11:36:32.0
facilitates data abstraction2001-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();
}   
2001-10-19 11:36:32.0
has example
//Example of constructor for the class Stack
public Stack() {
items = new Vector(10);
}
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    2001-10-19 11:36:32.0
has typically 1 or more arguments that determine some of the values of the variables of the class2001-10-19 11:36:32.0
is not a member2001-10-19 11:36:32.0
is not a method2001-10-19 11:36:33.0
is called when the new operator is used to create an instance of a class2001-10-19 11:36:33.0
is not inherited by a subclass2001-10-19 11:36:33.0
is part of class    2001-10-19 11:36:33.0
may have access modifier 2001-10-19 11:36:33.0
normally calls the zero-parameter constructor in the direct superclass first2001-10-19 11:36:33.0
provides a way to initialize a new object2001-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

Next constructorconstructor with no parameters    Upconstructor