Classes and Objects
Trail: Learning the Java Language

Lesson: Classes and Objects

With the knowledge you now have of the basics of the Java programming language, you can learn to write your own classes. In this lesson, you will find information about defining your own classes, including declaring member variables, methods, and constructors.

You will learn to use your classes to create objects, and how to use the objects you create.

This lesson also covers nesting classes within other classes, enumerations, and annotations.

Classes

This section shows you the anatomy of a class, and how to declare fields, methods, and constructors. This section covers issues relating to class hierarchies: how to override methods, hide methods or member variables, how to use super, the use of final to prevent subclassing, the use of abstract methods and classes. -->

Objects

This section covers creating and using objects. You will learn how to instantiate an object, and, once instantiated, how to use the dot operator to access the object's instance variables and methods.

More on Classes

This section covers more aspects of classes that depend on using object references and the dot operator that you learned about in the preceding section: returning values from methods, the this keyword, class vs. instance members, and access control.

Nested Classes

Static nested classes, inner classes, anonymous inner classes, and local classes are covered.

Enum Types

This section covers enumerations, specialized classes that allow you to define and use sets of constants.

Annotations

Annotations allow you to add information to your program that is not actually part of the program. This section describes three built-in annotations that you should know about. Even if you don't plan to write a generic type or a generic method, you will very likely encounter generics when you use Java SE API. This section tells you how to understand, and use, the syntax of generics. For information on how to write a generic type or method, see Generics by Gilad Bracha. -->


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Previous Lesson
Next page: Classes



Spec-Zone.ru - all specs in one place