• Post Reply Bookmark Topic Watch Topic
  • New Topic

creation of object  RSS feed

 
laxmidhar prad
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir
without using new ,can we create object or not
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough. You can change your display name here. Thanks!
 
Jody Brown
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.newInstance() should do the same thing.
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by laxmidhar:
sir
without using new ,can we create object or not


Why do you ask?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can define your own static newObj() method....

where you have a static global arr[] and as you call newObj,

you decrement down the arr[] and assign that certain object(of whatever

type you want) that type...

This is how they did it in the "old" days...

so i'm told

Justin
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:
you can define your own static newObj() method....

where you have a static global arr[] and as you call newObj,

you decrement down the arr[] and assign that certain object(of whatever

type you want) that type...

This is how they did it in the "old" days...

so i'm told

Justin


Please excuse my apparent ignorance, but wtf?
Can you please elaborate on whatever it is you are trying to say?
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not in Java. Sometimes it is a little hidden like a factory or singleton pattern implementation, but at the point where an object is created, there is a new there. This is not the case in C++ though, which causes confusion sometimes.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rusty Shackleford:
Not in Java. Sometimes it is a little hidden like a factory or singleton pattern implementation, but at the point where an object is created, there is a new there. This is not the case in C++ though, which causes confusion sometimes.


Find the "new" in Class.newInstance. You'll find it calls a native method, so it is possible. For the average developer, new is the only way.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = "Joe";

Heh...I just created an object without using the new keyword.

There are exceptions to every rule. Rules are just coathangers for exceptions.

But I like the new keyword. Don't see why I'd stop using it.

-Cameron
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kameron McKenzie:
String s = "Joe";

Heh...I just created an object without using the new keyword.

There are exceptions to every rule. Rules are just coathangers for exceptions.

But I like the new keyword. Don't see why I'd stop using it.

-Cameron


Did you really? It's entirely possible you didn't create anything but a reference to an existing object.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that may or may not create a new object. But it's an exception to "for the average developer, new is the only way." Here's another:

That does end up being equivalent to

but in terms of Java source code, it's not using "new". I'm not sure if that counts, depending on what the original poster really wants. I think Dana's question is fairly important here: laxmidhar, why do you ask? We can debate minutae about borderline cases, but without a meaningful context for the question, it doesn't much matter, I think.
[ September 01, 2006: Message edited by: Jim Yingst ]
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Blair:

Find the "new" in Class.newInstance.


Class.newInstance
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!