Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What data type is a string?

958


How many types of variables are there?

1080


How is garbage collection controlled?

1114


Can a class extend more than one class?

1052


What are the elements of java?

967


What are the types of casting?

1006


What is the difference between a local variable and an instance variable?

1016


Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?

982


What is the use of math abs in java?

959


How do you allocate memory to object?

924


When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

982


What do you mean by flow of struts?

1224


Explain aggregation in java?

920


Are constructors methods?

953


Can we able to pass objects as an arguments in java?

964