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

constructor with no parameters
subjectfact 
constructor with no parametersis a subtopic of Constructors2001-10-19 11:36:33.0
is a kind of constructor2001-10-19 11:36:33.0
must be defined if you define a constructor with parameters and you create instances using a constructor with no argumentsadded by: JK, source: On To Java, 2001-10-19 11:36:33.0
constructoralways have the same name as the class2001-10-19 11:36:32.0
can 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 have a return type2001-10-19 11:36:32.0
does not have a return type since it does not return a value2001-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 the same name as its class2001-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 constructordefault constructor    Upconstructor