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
1 4.2 Class with Methods
3 5
We will need to compile CreateAccount by means of the command
>
javac CreateAccount.java
Then we can run the program
>
java CreateAccount
A/c no: 123 A/e name: Fred Balance: 50.0
4.2 Class with Methods
As we have already mentioned, as well as member variables defining its state, a class can have
methods defining its behavior. A method is similar to a procedure or function in a nonobject-
oriented programming language. For our bank account class, examples of methods are deposit
and withdraw. The following is code for the deposit method that increases the balance by the
amount deposited:
public void
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

Hari Mohan Pandey
Java Programming

Java Programming

Poornachandra Sarang
JAVA Programming

JAVA Programming

K. Rajkumar
Java 9 for Programmers

Java 9 for Programmers

Paul J. Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781558609099