Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create object Without new operator

 
Manoj Paul
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

****************************************

code:


import java.io.*;

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));

name=name.replace('a','s');
System.out.println("My name is = "+name);
}

public static void main(String args[])
{
AQuestion7 object = new AQuestion7();
object.check();
}
}


****************************************
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can you reflection to create objects without the new operator.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
substring returns a new Object
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic