Skip to Main Content
Java
book

Java

by Michael Sikora
January 2003
Beginner to intermediate content levelBeginner to intermediate
150 pages
7h 28m
English
Morgan Kaufmann
Content preview from Java
m
4.3 Constructors
37
13 } else {
14 balance = balance - amount;
15 }
16 return balance;
17 }
18 }
Account
The syntax for invoking a method is
object_identifier.method(optional arguments);
An example of statements invoking the deposit and withdraw methods of the Account class is
fredsAccount, deposit (100) ;
amountLeft = fredsAccount.withdraw(120) ;
where amountLeft is a variable of type double.
4.3 Constructors
Java provides a special kind of method, called a constructor, that executes each time an
instance of an object is created. The constructor can be used to initialize the state of an object.
The call to
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Programming

Java Programming

Poornachandra Sarang
JAVA Programming

JAVA Programming

K. Rajkumar
Java Programming

Java Programming

Hari Mohan Pandey
Java 9 for Programmers

Java 9 for Programmers

Paul J. Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781558609099