when we write class.forName("any one class"); what happens
actually?what it will return?explain stepwise?

Answers were Sorted based on User's Feedback



when we write class.forName("any one class"); what happens actually?what it will return?..

Answer / raviji

When we user Class.forName("any one class"); in out program
then actually we tell to JVM to load this class for
connectivity to the DB with out program.

Is This Answer Correct ?    4 Yes 0 No

when we write class.forName("any one class"); what happens actually?what it will return?..

Answer / ram

Class.forName () takes the class name as parameter, and
loads that class in memory. But it doesn't create any
instance of that class.

Is This Answer Correct ?    2 Yes 0 No

when we write class.forName("any one class"); what happens actually?what it will return?..

Answer / paras

Class.forName("")loads that class in memory ,to create
instance we have to use newInstance()

string _path="classpath loc of class XYZ ex com.aa.ss.XYZ";

Object ob=Class.forName(_path).newInstance();;
((XYZ)ob).any_method_of_XYZ();

Is This Answer Correct ?    2 Yes 0 No

when we write class.forName("any one class"); what happens actually?what it will return?..

Answer / raghu

When Class.forNmae("className") is executed, the class will
be loaded, as soon as the class is loaded the static block
will be executed.In the static block the thngs will happen.

Is This Answer Correct ?    0 Yes 0 No

when we write class.forName("any one class"); what happens actually?what it will return?..

Answer / bharat

when we write the statement
Class.forName("fully qualified path for the class");
then the above statement will do the following things:->
1. loads the specified class (if found) in the memory otherwise throws ClassNotFoundException
2. Returns the object of type java.lang.Class corresponding to the class that was loaded ,In actual this returned object contains all properties of the class that was loaded, In technical words we will say that it is the reflection of the actual class, we can now access all the information about the loaded class with the help of this Class class object, we can now access all the data members , member methods whether they are private or public, all constructors, names of its parent classes, parent Interfaces etc with the help of this Class class object.

Is This Answer Correct ?    0 Yes 0 No

when we write class.forName("any one class"); what happens actually?what it will return?..

Answer / gaurav agrawal

why are you misguiding the people, class.forName("") create
the instance of the class given as argument of the forName
().
first it will load the class in the JVM and after that it
will create the instance.

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More Core Java Interview Questions

public class Test { public static void main(String ar[]) { Integer a = 10; Integer b =10; Integer c = 145; Integer d = 145; System.out.println(a==b); System.out.println(c==d); } }

7 Answers   iGate,


What is mysql driver class name?

0 Answers  


What is factor r?

0 Answers  


What does the “final” keyword mean in front of a variable? A method? A class?

0 Answers  


Do you need to import math in java?

0 Answers  






How many types of methods are there in java?

0 Answers  


Why can't we override private static methods?

0 Answers  


Can a class have 2 constructors?

0 Answers  


Where is core java used?

0 Answers  


What is the purpose of the file class in java programming?

0 Answers  


What is xslt in java?

0 Answers  


Can we use this () and super () in a method?

0 Answers  


Categories