23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Class modifiers are optional keywords that precede the class keyword. We have<br />

already seen examples that use the public keyword. In general, the different class<br />

modifiers <strong>and</strong> their mean<strong>in</strong>g is as follows:<br />

• The abstract class modifier describes a class that has abstract methods.<br />

Abstract methods are declared with the abstract keyword <strong>and</strong> are empty (that<br />

is, they have no block def<strong>in</strong><strong>in</strong>g a body of code for this method). A class that has<br />

noth<strong>in</strong>g but abstract methods <strong>and</strong> no <strong>in</strong>stance variables is more properly called an<br />

<strong>in</strong>terface (see Section 2.4), so an abstract class usually has a mixture of<br />

abstract methods <strong>and</strong> actual methods. (We discuss abstract classes <strong>and</strong> their uses<br />

<strong>in</strong> Section 2.4.)<br />

• The f<strong>in</strong>al class modifier describes a class that can have no subclasses.<br />

(We will discuss this concept <strong>in</strong> the next chapter.)<br />

• The public class modifier describes a class that can be <strong>in</strong>stantiated or<br />

extended by anyth<strong>in</strong>g <strong>in</strong> the same package or by anyth<strong>in</strong>g that imports the<br />

class. (This is expla<strong>in</strong>ed <strong>in</strong> more detail <strong>in</strong> Section 1.8.) Public classes are declared<br />

<strong>in</strong> their own separate file called classname. java, where "classname" is the<br />

name of the class.<br />

• If the public class modifier is not used, the class is considered friendly.<br />

This means that it can be used <strong>and</strong> <strong>in</strong>stantiated by all classes <strong>in</strong> the same package.<br />

This is the default class modifier.<br />

1.1.1 Base Types<br />

The types of objects are determ<strong>in</strong>ed by the class they come from. For the sake of<br />

efficiency <strong>and</strong> simplicity, <strong>Java</strong> also has the follow<strong>in</strong>g base types (also called<br />

primitive types), which are not objects:<br />

boolean<br />

Boolean value: true or false<br />

char<br />

16-bit Unicode character<br />

byte<br />

8-bit signed two's complement <strong>in</strong>teger<br />

short<br />

16-bit signed two's complement <strong>in</strong>teger<br />

21

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!