|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The first bold line in the following listing begins a class definition block./** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. } }A class--the basic building block of an object-oriented language such as Java--is a template that describes the data and behavior associated with instances of that class. When you instantiate a class you create an object that looks and feels like other instances of the same class. The data associated with a class or object is stored in variables; the behavior associated with a class or object is implemented with methods. Methods are similar to the functions or procedures in procedural languages such as C.
As an example, consider a class that represents a rectangle. The class would contain variables for the origin of the rectangle, its width, and its height. The class might also contain a method that calculates and returns the area of the rectangle. An instance of the rectangle class would contain the information for a specific rectangle, such as the dimensions of the floor of your office, or the dimensions of this page.
In the Java programming language, the simplest form of a class definition is
class name { . . . }The keyword
classbegins the class definition for a class namedname. The variables and methods of the class are enclosed within the curly brackets that begin and end the class definition block. The "Hello World" application has no variables and has a single method namedmain.For more information about object-oriented concepts, see Object-Oriented Programming Concepts
. To learn how object-oriented concepts are implemented in the Java language, see Classes and Inheritance
.
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.