Java Reference
In-Depth Information
The art of object-orientation starts with learning how to think objects.
Consider the following Java program:
On the Web
The source file for the program VirtualDog.java can be found in the
Chapter15folderat www.crcpress.com .
//************************************************************
// File name: VirtualDog.java
// Reference: Chapter 15
//************************************************************
//
//
Java program to demonstrate a classes and objects
//
Topics:
//
1. Java application with multiple classes
//
2. Object instantiation
//
//
Note:
//
1. Only one class in a file can be public. The public
//
class must have the name of the Java source file.
//
2. The "this" operator refers to the current object.
//
3. Class variables are usually declared with private
//
accesibility in order to preserve encapsulation
//***********************************
//***********************************
// CLASS Dog
//***********************************
//***********************************
class Dog
{
// Class variables
private int dogNum; // Dog object number
private String dogName; // Dog object name
//************************
// setDogData()
//************************
public void setDogData(int aNum, String aName)
{
this.dogNum = aNum;
this.dogName = aName;
}
//************************
// method bark()
//************************
public void bark()
{
System.out.println("Arf!, Arf!");
}
Search WWH ::




Custom Search