Object Oriented Software Engineering   View all facts   Glossary   Help
subject > component > module > Java module > Java method > Java constructor
Upconstructor, Java method

Java constructor comparison table
Subject lack have have advantage be return to is part of is a kind of is a subtopic of have example override hide have purpose perform access by has definition have high cohesion
constructor one or more preconditions   a classprocedureThe Basics of Java   to initialize the instance variables of a newly created object and perform any other needed initialization  A procedure that is called whenever a new object is created 
Java methodside effects if it does not modify any data, and does not leave behind any information, other than its result, that would have an effect on other computationsa comment at its head if the method is non-obviouswhen using a certain procedure, a programmer does not need to worry about all the details of how it performs its computations; he or she only needs to know how to call it and what it computespublic except for those that will definitely need to be called from outside the packageits caller from only one place which should be the last statement method9.1 - The Process of Design a method in a superclass with the same namethe details of procedures a special-purpose function such as the user interface for a particular systemother methods and variables in any class in the same package by default if related aspects of a system are kept together in this module, and unrelated aspects are kept out
Java constructorside effects if it does not modify any data, and does not leave behind any information, other than its result, that would have an effect on other computationsthe same name as its classwhen using a certain procedure, a programmer does not need to worry about all the details of how it performs its computations; he or she only needs to know how to call it and what it computespublic except for those that will definitely need to be called from outside the packageits caller from only one place which should be the last statementa classJava methodThe Basics of Java
public Account(String accountHolder, float initialBalance)
{
this.accountHolder = accountHolder;
balance = initialBalance;
opened = new Date();
}
public Account(String accountHolder)
{
this.accountHolder = accountHolder;
balance =0.0;
opened = new Date();
}
a method in a superclass with the same namethe details of proceduresto initialize the instance variables of a newly created object and perform any other needed initializationa special-purpose function such as the user interface for a particular systemother methods and variables in any class in the same package by default if related aspects of a system are kept together in this module, and unrelated aspects are kept out

Upconstructor, Java method