The getResource() method of java.lang.Class class is used to get the resource with the specified resource of this class. The method returns the specified resource of this class in the form of URL object.
public URL getResource(String resourceName)
Parameter: This method accepts a parameter resourceName which is the resource to get.
Return Value: This method returns the specified resource of this class in the form of URL objects.
Exception This method throws:
- NullPointerException if name is null
Below programs demonstrate the getResource() method.
Class represented by myClass: class Test obj resource of myClass: null
Class represented by myClass: class Main obj resource of myClass: null
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.