Documentation

The Java™ Tutorials
Hide TOC
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.有了Java编程语言的基础知识,您可以学习编写自己的类。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, and enumerations本课程还将介绍在其他类中嵌套类以及枚举

Classes

This section shows you the anatomy of a class, and how to declare fields, methods, and constructors.本节向您展示了类的结构,以及如何声明字段、方法和构造函数。

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.您将学习如何实例化对象,以及一旦实例化,如何使用dot运算符访问对象的实例变量和方法。

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:本节介绍了依赖于使用对象引用和dot运算符的类的更多方面,这些对象引用和点运算符是您在上一节中了解的: returning values from methods, the this keyword, class vs. instance members, and access control.从方法、this关键字、类与实例成员以及访问控制返回值。

Nested Classes内部类

Static nested classes, inner classes, anonymous inner classes, local classes, and lambda expressions are covered.本文介绍了静态嵌套类、内部类、匿名内部类、局部类和lambda表达式。There is also a discussion on when to use which approach.还讨论了何时使用哪种方法。

Enum Types枚举类型

This section covers enumerations, specialized classes that allow you to define and use sets of constants.本节介绍枚举,即允许您定义和使用常量集的专用类。


Previous page: Previous Lesson
Next page: Classes