1. Computing & Technology

Discuss in my forum

Designing and Creating Objects

By , About.com Guide

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.

©2012 About.com. All rights reserved.

A part of The New York Times Company.