Home » Java programming language

Java ClassLoader resolveClass() method with example

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

ClassLoader Class resolveClass() method

  • resolveClass() method is available in java.lang package.
  • resolveClass() method is used to link the specified class let suppose when class A has been linked already then in that case this method simply returns.
  • resolveClass() 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.
  • resolveClass() method may throw an exception at the time of linking class.
    NullPointerException: In this exception when the given class is null.

Syntax:

    protected void resolveClass(Class cl_name);

Parameter(s):

  • Class cl_name – represents the name of the class to link.

Return value:

The return type of this method is void, it returns nothing.

Example:

// Java program to demonstrate the example 
// of void resolveClass(Class cl_name) method of ClassLoader 

public class ResolveClass extends ClassLoader {
 ResolveClass(Class cl1) {
  // By using super keyword to call parent class
  // Constructor
  super.resolveClass(cl1);

  // Display Resolve Class Name
  System.out.println("Class Name: " + cl1.getSimpleName());
 }

 public static void main(String[] args) throws Exception {
  // We are parsing Class to ClassLoader constructor
  Class cl = Class.forName("java.lang.String");

  // Calling ResolveClass Constructor
  ResolveClass rc = new ResolveClass(cl);
 }
}

Output

Class Name: String



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.