ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
How to create an instance of a class without using "new"
operator? Plz help me out properly.Thank u.
 Question Submitted By :: Tanzeem.akhtar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 1
In java without using new you can not create instance of a 
class.
 
Is This Answer Correct ?    6 Yes 14 No
Arun Kumar Rout
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 2
By using Class d=Class.forName("className");
Object obj=c.newInstance();
 
Is This Answer Correct ?    24 Yes 1 No
Saravanan P
 
 
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 3
yes ....Class is a class which creates object 
dynamically.....
 
Is This Answer Correct ?    2 Yes 2 No
Eswar
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 4
three types
1.using factory methods
  NumberFormat obj = NumberFormat.getNumberInstance();
2. using newInstance() method
  class c = class.forName("Employee");
  Employee obj = c.newInstance();
3. using coloning:
coloning is a way to create Bitwise exactcopy of an 
existing object
Employee e2=e1.clone();
 
Is This Answer Correct ?    6 Yes 2 No
B S Vidyasagar Reddy
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 5
Dynamic loading is a technique for programmatically 
invoking the functions of a class loader at run time. 

Let us look at how to load classes dynamically.

Class.forName (String className); //static method which 
returns a Class
The above static method returns the class object associated 
with the class name. 
The string className can be supplied dynamically at run 
time. 
Once the class is dynamically loaded the following method 
returns an instance of the loaded class. It’s just like 
creating a class object with no
arguments.
class.newInstance (); //A non-static method, which creates 
an instance of a
//class (i.e. creates an object).

Example as shown below .... 

Test test = null ;
String myClassName = "com.test.DynamicLoadingClass" ;
Class testClass = Class.forName(myClassName) ;
test = (Test) testClass.newInstance();
 
Is This Answer Correct ?    2 Yes 1 No
Satchidananda.lanka
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 6
with out new operater we can create object. Because the 
String varible is taken as an object in java, which is 
created  with out new operater.
ex.
   String str="xxxx";
 
Is This Answer Correct ?    1 Yes 0 No
Xxxx
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 7
by using class.forName();
 
Is This Answer Correct ?    0 Yes 0 No
Guest
 
  Re: How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.
Answer
# 8
This is happening using reflection. Read reflection in java
 
Is This Answer Correct ?    1 Yes 0 No
Prakash Sah
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What are the standards to place package statement within a source code file?  1
By what default value is an object reference declared as an instance variable? Wipro1
What is a Java package and how is it used?  2
How to initialize an Applet ? TCS6
How does Vector implement synchronization? Ness-Technologies2
adapter class ?  2
What is adapter class?  2
What methods are called, When we navigate from one applet to another applet?  1
Why to give the file name same as the public class name in java?  3
what is the use of servlet engine? Photon2
What are the latest versions in JAVA related areas? Netcraft2
can u handle an error if u write Thowable in the catch class lise try { some errorneous code }catch(Throwable e){ ...}  4
What is meant by constructor?  4
How the elements are organized in GridBagLayout?  1
What is the difference between C++ & Java? Syntel21
What is a default package ?  7
how to call a method in different package?  4
What classes of exceptions, thrown by a throw statement?  2
How many bits are allocated to represent character of character sets - Unicode, ASCII, UTF-16, UTF-8?  1
Without creating a new object, How you can retrieve a String or other object?  1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com