Section A.7. Classes


[Page 548 (continued)]

A.7. Classes

Each class is usually defined in a separate file with the same name as the class name followed by '.java'. The convention is to uppercase the first letter of all words in a class name.

The syntax to declare a class is:

visibility class Name {    // fields, constructors, and methods }


You can also specify the parent class using the extends keyword. If no parent class is specified, it will be java.lang.Object. A child class inherits public and protected fields and methods.

visibility class Name extends ParentName {    // fields, constructors, and methods }


A class can also implement several interfaces. The list of interfaces is separated by commas and follows the specification of the parent class if given.

visibility class Name extends ParentName    implements Interface1, Interface2, ... {    // fields, constructors, and methods }


Here is an example class declaration. The Student class will inherit from the Object class.

public class Student {    // fields, constructors, and methods }




Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net