The moose likes Java in General and the fly likes Create object Without new operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create object Without new operator" Watch "Create object Without new operator" New topic

Create object Without new operator

Manoj Paul
Ranch Hand

Joined: Jan 18, 2007
Posts: 112
Here is my program.
An object 'object' is created using the new operator.
I want to create an object without using the new operator.
Can you suggest how?




public class AQuestion7
String name="Manoj Kumar Paul";

public void check()
System.out.println("Substring = "+name.substring(0));
System.out.println("Substring = "+name.substring(9));
System.out.println("Substring = "+name.substring(0,5));

System.out.println("My name is = "+name);

public static void main(String args[])
AQuestion7 object = new AQuestion7();

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You can you reflection to create objects without the new operator.

Rahul Bhattacharjee
LinkedIn - Blog
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

substring returns a new Object
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Consider Paul's rocket mass heater.
subject: Create object Without new operator
It's not a secret anymore!