Java.lang.ClassLoader.getParent() Method

Advertisements


Description

The java.lang.ClassLoader.getParent() method returns the parent class loader for delegation. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class loader's parent is the bootstrap class loader.

Declaration

Following is the declaration for java.lang.ClassLoader.getParent() method

public final ClassLoader getParent()

Parameters

  • NA

Return Value

This method returns the parent ClassLoader

Exception

  • SecurityException -- If a security manager exists and its checkPermission method doesn't allow access to this class loader's parent class loader.

Example

The following example shows the usage of java.lang.ClassLoader.getParent() method.

package com.tutorialspoint;

import java.lang.*;

public class ClassLoaderDemo {

  public static void main(String[] args) throws Exception {
     
    Class cls = Class.forName("ClassLoaderDemo");

    // returns the ClassLoader object associated with this Class
    ClassLoader cLoader = cls.getClassLoader();
    
    System.out.println(cLoader.getClass());
    
    // returns the parent ClassLoader
    System.out.println(cLoader.getParent());
  }
} 

Let us compile and run the above program, this will produce the following result:

class sun.misc.Launcher$AppClassLoader
sun.misc.Launcher$ExtClassLoader@35ce36



Advertisements
Advertisements