• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to dynamically create objects in java  RSS feed

 
pratik doshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the requirements are s follows:
the user enters his employee enters his employee id and name and this goes on

after he finishes entering a new object should be created of class employee.
again when next user enters the details another object of employee should be created.
and this goes on in a loop until the user types exit.

my query is how to create objects of class employee in a loop.

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't create a Class, you're creating an instance of a Class

Employee emp = new Employee();
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want new objects in a loop? Are you filling an array or something?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pratik doshi wrote:my query is how to create objects of class employee in a loop.

What exactly is your question: how to create objects, or how to create a loop? If you know how to create objects, you also know how to do it in a loop, because it isn't different when you do it in a loop. Maybe you want to know how to store all those objects that you create inside a loop. You'll want to use a collection for that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!