who can we create the object of a class? in how many ways we
can create it (max 5)

Answers were Sorted based on User's Feedback



who can we create the object of a class? in how many ways we can create it (max 5)..

Answer / chandni jain

1. Using new keyword
This is the most common way to create an object in java.

MyObject object = new MyObject();

2. Using Class.forName()
If we know the name of the class & if it has a public
default constructor we can create an object in this way.

MyObject object = (MyObject)
Class.forName("subin.rnd.MyObject").newInstance();

3. Using clone()
The clone() can be used to create a copy of an existing object.

MyObject anotherObject = new MyObject();
MyObject object = anotherObject.clone();

4. Using object deserialization
Object deserialization is nothing but creating an object
from its serialized form.

ObjectInputStream inStream = new
ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();

Is This Answer Correct ?    4 Yes 0 No

who can we create the object of a class? in how many ways we can create it (max 5)..

Answer / ravi jain

through

1) String s = "This is my Object";

2) String s1 = s.subString(1,8);

3) int[] arr = {12,45,12}; every array is an object.

4) String s2 = s + s1;

these all are also create new instances.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

Difference between JVM and JRE?

3 Answers   Amdocs,


Why packages are used?

1 Answers  


Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?

1 Answers  


Java support what type of parameter passing ?

7 Answers   Wipro,


Is double bigger than float?

0 Answers  






can u handle an error if u write Thowable in the catch class lise try { some errorneous code }catch(Throwable e){ ...}

4 Answers  


I have one Shopping cart application, i that i have selected some items, while clicking submit button by mistake i have clicked twice or trice, that time items are selected twice or trice. Actually i want only one copy of items but its selected twice or trice. So how can we avoid this problem?

2 Answers   Honeywell,


What is lazy activation?

2 Answers   CMC,


How to sort double array in java?

0 Answers  


public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int countF = 0; int countG = 0; int countH = 0; int countI = 0; int countJ = 0; int countK = 0; int countL = 0; int countM = 0; int countN = 0; int countO = 0; int countP = 0; int countQ = 0; int countR = 0; int countS = 0; int countT = 0; int countU = 0; int countV = 0; int countW = 0; int countX = 0; int countY = 0; int countZ = 0; } } Can anybody tell me any alternate solution(like loop or something) to automate this initialization process. Ex:- for(char chr='A';chr<='Z'; chr++) { (int) String "count"+chr = 0; }

0 Answers  


Write a java program that prints all the values given at command-line.

0 Answers  


What is return in java?

0 Answers  


Categories