Class Class
Package: java.lang
Every class used by a Java application is represented in memory by an object of type Class. If your program uses Employee objects, for example, there’s also a Class object for the Employee class. This Class object contains information not about specific employees, but about the Employee class itself.
Methods
|
Method |
Description |
|
|
Returns the name of the |
|
|
Returns a |
Getting a Class object
Because Class objects are created by the Java runtime, the Class class has no public constructor. You can get a Class object by using the getClass method. The Object class defines this method, so it’s available to every object. (See Object Class.)
For example:
Employee emp = new Employee();
Class c = emp.getClass();
Suppose that an HourlyEmployee class extends the Employee class. Then consider these statements:
HourlyEmployee emp = new Employee();
Class c = emp.getClass();
Here, c refers to a Class object for the HourlyEmployee ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access