• Post Reply Bookmark Topic Watch Topic
  • New Topic

Different ways to create Objects  RSS feed

 
Rohit Sajan
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the different ways to create Objects in Java? Could anyone help on this?
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you posted this as an "advanced" question?

As far as I can remember you can get an Object by:-
  • Invoking its constructor with the new operator/keyword [Foo myFoo; . . . myFoo = new Foo();]
  • Retrieve an object which has been previously stored (Serialized) or transmitted (also Serialized).
  • Retrieve a previously stored object from a bean.
  • Use the Class class. [Foo myFoo; . . . myFoo = (Foo) Class.forName("mypackage.Foo").getInstance();]

  • There may be more.
    Please check the spelling of the methods carefully with the API website before you use any of these suggestions.

    CR
     
    Jesper de Jong
    Java Cowboy
    Sheriff
    Posts: 16060
    88
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Try doing a search in the forums. Your question has been asked before. (Is this some kind of standard question for interviews or an exam somewhere?).
    [ March 07, 2007: Message edited by: Jesper Young ]
     
    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
    Boost this thread!