There are 2 different ways to create an object. a)By using
keyword "new" b)By using Class.forName
("className").newInstance();
What is the difference between these 2 methods.
Answer Posted / qim2010
Java’s “new” operator is used to load the class statically.
class MyClass {
public static void main(String args[]) {
Car c = new Car();
}
}
Class.forName (String className); is used for dynamic class
loading. 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).
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Is break statement can be used as labels in java?
How can u increase the heap size in the memory?
Can we convert list to set in java?
What is another word for methodology?
What is method overloading with type promotion?
How many bytes is a unicode character?
Is java a prime method?
What is a default constructor and also define copy contrucyor?
What is integers and example?
What is callable java?
Explain the difference between abstraction and encapsulation.
Mention some interfaces implemented by linked list in java.
What is meant by attribute?
Explain about assignment statement?
What is the difference between dom and sax parser in java?