Programming and Problem Solving with Java

(やまだぃちぅ) #1
2.1 The Elements of Java Programs | 51

turns an object of the class type. The object that is returned is an instance of the class. The
act of creating an object from a class is called instantiation.
The following definitions provide new meanings for the terms objectand class in addi-
tion to how we defined them in Chapter 1:


Class (general sense) A description of the behavior of a group of objects with similar
properties and behaviors
class(Java construct) A pattern for an object

Object (general sense) An entity or thing that is relevant in the context of a problem

Object (Java) An instance of a class

Instantiation Creating an object, which is an instance of a class

Method A subprogram that defines one aspect of the behavior of a class

Here is the syntax diagram for a class:

Our class declaration template looks identical to the template for a Java application be-
cause a Java application is just a class that has a method called main. We look specifically at
construction of an application later in this chapter. Here we are interested in those aspects
of defining a class that apply to all Java classes.


private

public

Class-Modifiers

Import-Declaration;...

Class-Modifiers...

Class-Declaration...

Class

{

class Identifier

}
Free download pdf