Find the Package of an Object

This example shows how to determine the package of an object. To get the package name we need to call the getClass() method of the object to get a reference to the object class.
Then we can call the getPackage() method that will return an object of type Package. Finally we call the getName() method on the Package object which returns a String containing the package name.

This code will result in the following output:

Search for more Java info on this site here:
Custom Search

Please type any questions here.