Class encapsulates the run-time state of an object or interface. Objects of type Class me created automatically, when classes are loaded. You cannot explicitly declare a Class object. Generally, you obtain a Class object by calling the get Class( ) method defined by Object. Some of the most commonly used methods defined by Class are shown in Table 14-13.

The methods defined by Class are often useful in situations where run-time type information about an object is required. As Table 14-13 shows, methods are provided that allow you to determine additional information about a particular class, such as its public constructors, fields, and methods. This is important for the Java Beans functionality, which is discussed later in this book. The following program demonstrates get Class( ) (inherited from Object) and get Super class( ) (from Class):

The output from this program is shown here:

x is object of type:   X
y is object of type:   Y
y’s super class is       X

Class Loader

The abstract class Class Loader defines how classes arc loaded. Your application can create sub classes that extend Class Loader, implementing its methods. Doing so allows you to load classes in some way other than the way they arc normally loaded by the Java run-time system. Some of the methods defined by Class Loader are shown in Table


The Math class contains all the floating-point functions that are used for geometry and trigonometry, as well as several general-purpose methods. Math defines two double constants: E (approximately 2.72) and PI (approximately 3.]4).

reCAPTCHA is required.

Share This