Preview

AP Computer Science- Classes

Better Essays
Open Document
Open Document
939 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
AP Computer Science- Classes
Defining Java Classes
I. A class is a collection of types and methods that all somehow work together.
II. The general syntax for defining a class is shown here. It may look complicated, because it’s written in very general form here, but it’s very simple.

i. The square brackets in this syntax indicate optional things. ii. The first component of the class definition is called the access_mode. It will either be public, abstract, final, or not used at all. iii. Then comes the class keyword, and then the name of the class. iv. Names for Java classes follow the same rules as for variable names. It is convention that each word in the class name begins with an upper case letter.
v. The body of the class is contained within a set of braces, and typically consists of type declarations…which are often referred to as the data members of the class, method definitions, and sometimes even other class definitions. vi. And, the body of the class defines a scope.
III. The variables, methods, and classes that are part of the class definition are commonly called class members.

Declaring Class Member Variables
I. This is the general syntax for declaring the variables associated with a class.

i. The first element is the access mode. It can be public, private, protected, or not appear at all. ii. The optional keyword static is used to declare a special kind of variable called a class variable. Class variables will be discussed in another lecture. iii. The type name is the name of a primitive or non-primitive type. iv. And the variable name is the name of the variable.
Defining Class Member Methods
I. This is the general syntax for declaring the methods associated with a class.

i. The first element is the access mode. It can be public, private, protected, or not appear at all. ii. The optional keyword static is used to declare a special kind of method called a class method. (Actually, all the methods I’ve asked you to write so far in this

You May Also Find These Documents Helpful

Related Topics