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
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 |
Difference between JVM and JRE?
Why packages are used?
Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?
Java support what type of parameter passing ?
Is double bigger than float?
can u handle an error if u write Thowable in the catch class lise try { some errorneous code }catch(Throwable e){ ...}
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?
What is lazy activation?
How to sort double array in java?
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; }
Write a java program that prints all the values given at command-line.
What is return in java?