1. Home
  2. Computing & Technology
  3. Java

Designing and Creating Objects

By Paul Leahy, About.com

2 of 7

The Class Declaration

The data an object holds and how it manipulates that data is specified through the creation of a class. For example, below is a very basic definition of a class for a Book object:

public class Book {


}

It's worth taking a moment to break down the above class declaration. The first line contains the two Java keywords "public" and "class":

  • The public keyword is known as an access modifier. It controls what parts of your Java program can access your class. In fact, for top-level classes (i.e., classes not contained within another class), like our book object, they have to be public accessible.
  • The class keyword is used to declare that everything within the curly brackets is part of our class definition. It's also followed directly by the name of the class.

Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java
  4. Java Syntax
  5. Working With Objects
  6. The Class Declaration

©2009 About.com, a part of The New York Times Company.

All rights reserved.