Home » Java programming language

Java Class class getClasses() method with example

Class class getClasses() method: Here, we are going to learn about the getClasses() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 04, 2019

Class class getClasses() method

  • getClasses() method is available in java.lang package.
  • getClasses() method is used to return an array that contains Class objects denoting all the public classes and interfaces that are a member of the class denoted by this Class object and it includes public class and interface members inherited from parent classes.
  • getClasses() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getClasses() method may throw SecurityException at the time of checking security constraints.SecurityException: This exception raise when security manager exists.


    public Class[] getClasses();


  • It does not accept any parameter.

Return value:

The return type of this method is Class[], it returns an array of Class objects denoting the public members of this class.


// Java program to demonstrate the example 
// of Class[] getClasses() method of  Class 

public class GetClassesOfClass {
    public static void main(String[] args) throws Exception {
        // It returns the Class object attached 
        // with the given classname
        Class cl = Class.forName("java.lang.ClassLoader");

        // It returns an array of Class objects denotes the public
        // member of the class "java.lang.ClassLoader"
        Class[] public_classes = cl.getClasses();

        // Traversing ClassLoader class
        for (int i = 1; i <= public_classes.length; ++i) {
            System.out.print("Class Name: ");




Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.