Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shaik Jelani
object
2 Answer(s)      5 years and 6 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

May 5, 2009 at 10:47 AM


Hello,
i know only two wayes of object instansiations

1- MyClass mc = new MyClass();
2- MyClass mc1 = (MyClass) Class.forName("MyClass").newInstance();

if you know any other way then please repplly.

Thankx



May 5, 2009 at 11:13 AM


Hi Friend,

Yes we can create an object in the following different ways:

1. Using new operator :
This is the most general way of creating an object.
ClassName classObject = new ClassName();

2. Using Class.forName()
If you already know the name of the Class and it has its public default constructor. We can create the object in the

following manner :
ClassName classObject = (ClassName) Class.forName("packagename.ClassName").newInstance();

3. Using classLoader
this.getClass().getClassLoader().loadClass("packagename.ClassName").newInstance();

4. Using clone() method
We can use the clone() method to create the copy of the existing Object.
(e.g) ClassName firstObject = new ClassName();
ClassName secondObject = (ClassName) firstObject.clone();

5. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStream inStream = new ObjectInputStream(anInputStream );
ClassName classObject = (ClassName) inStream.readObject();


Thanks
RoseIndia Team


Related Tutorials/Questions & Answers:
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
object of object class
object of object class  what do u mean by "object of object class
Advertisements
object creation
object creation  when will java object is created? is it at runtime or compiletime
Object
Object       An object...). In an object, variables store values for later use and methods are the unit... are the basic units of the object-oriented programming. Objects are the part of our day
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Object reference not set to an instance of an object
Object reference not set to an instance of an object  Object reference not set to an instance of an object
Session Object
Session Object  Why do we require Session Object?  Hello.... The session object is used by the developers to store and retrieve user's related data such as login details. The javax.servlet.http.HttpSession object
object as argument
object as argument  what happens when we pass a object into a method???if java is pass by value how does this makes a difference.....pllzzz give me more clarification on why we pass objects in a margument
ArrayList object
ArrayList object  i have am ArrayList object it containg data base records in it, now i want to display this ArrayList object data in my jsp programe, plz help me
Object Creations
Object Creations  String a[][]=new String[10][20]; The above line how many objects are created
Java object
Java object  Which class should you use to obtain design information about an object
Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after it is created. This is as opposed to a mutable object, which can be modified
Session Object
Session Object   What is the Max amount of information that can be saved in a Session Object ?   There is no such limit on the amount of information that can be saved in a Session Object. The only limit is the Session
object array
object array  Hi i have array that is object[] obj= { new string("hi"), new vector().add(10), new hashmap().setkey()} display(obj); display(object{[] obj) {} Now my question is what is the string length and how to retrieve
Vector object[]
Vector object[]  I want to create payslip in java public Vector...(); Object[] value = new Object[] {"Employee Name",f.ename.getSelectedItem()}; rec.add(value); value = new Object[] {"Mary-Kate Olsen", "Ashley
constructor or object
constructor or object  object or construct which create first?   A constructor is always created first. Here is an example: class Example { Example(String st){ System.out.println(st); } public
implect object
implect object  how i implment implect object   Hi Friend, Please visit the following links: http://www.roseindia.net/help/java/o/jsp-implicit-objects.shtml http://www.roseindia.net/jsp/jspfundamentals.shtml Thanks
class and Object
class and Object  how many classes,References and objects in this following statement.... A a=new B();   Hi, In the statement: A a=new B(); There are 2 classes, Class A and Class B. References : 1 (Object of B
object and method
object and method  a college would like to automate managing courses offered to students. initially only three courses are involved. each courses has... and an application that creates the necessary object
Object slicing
Object slicing  I have a program as bellow: #include<iostream.h> #include<conio.h> class A { public: int x; A() { x=10; } }; class B:public A { protected: int y
Class and object
the object of subclass Thanks
Java Object
Java Object         Object is the basic entity of object oriented programming language. Object... properties of the class or its group. Java object is an instance of the class. It takes
What is an object's lock and which object's have locks?
What is an object's lock and which object's have locks?   Hi, What is an object's lock and which object's have locks? Thanks
View object in JSF
View object in JSF  What is view object
use of object tag
use of object tag  how to use object tag in html
implementation object in C
implementation object in C  how to create and implement an object in C
Potential leak of an object XCode
Potential leak of an object XCode  What is potential leak of an object XCode
assign object properties
assign object properties  How do you assign object properties
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
How to disable an HTML object?
How to disable an HTML object?  How to disable an HTML object
Java object clone
Java object clone  What is criteria for a object to get cloned
 

 

 

DMCA.com