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 is array size in java?

955


Can a abstract class be defined without any abstract methods?

997


Describe the syntax of multiple inheritance? When do we use such an inheritance?

1088


What is meant by 'Class access modifiers'?

1042


What is the access scope of a protected method?

1021


Can we define a package statement after the import statement in java?

1064


Can we inherit inner class?

1010


Difference between ‘>>’ and ‘>>>’ operators in java?

1122


What is an immutable class? How to create an immutable class?

1058


What are daemon Threads in java?

1192


Should database connections be singleton?

954


What is the purpose of static keyword in java?

956


Can I declare class as static or private?

960


What is difference between call by value and call by reference?

992


How to solve the problem of generating the unique hash keys with hash function?

1909