Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
can i create multiple objects in only one class.
Posted
Comments
DamithSL 6-Dec-14 3:06am    
What is your class? What you mean by only one class?
You better read the documentation first.[^]
BillWoodruff 6-Dec-14 3:09am    
It sounds like you are demanding something, rather than asking a question.
George Jonsson 6-Dec-14 4:37am    
Maybe add a please in the title when you improve your question with more info.
[no name] 6-Dec-14 9:24am    
yep you're completely right. I'm wondering that OP did not end it with a "!"
:-)
George Jonsson 6-Dec-14 22:36pm    
Maybe it was considered to be too rude. :)
But it looks like the OP is not happy that some people has spent their time to answer the question. Not even a comment, much less an accepted answer.

you can create any no of objects for a class.


see the example

C#
class sample
{
   //data members
   int a,b,c;
   float x,y,z;
   char m,n;
   string s;

   //constructor - optional
   sample() // name should be same as class name and no return value
   {
      a=0,b=1,c=2; // all I am doing is initializing values
   }

   //functions
   public void doX(parameters)
   {
     //do something
   }
   public void doY(parameters)
   {
     //do something
   }
}


class mainClass()
{
   sample s = new sample();
   sample t = new sample();
   // or even you can create no of objects at once
   sample[] listOfObjects = new sample[100]; // it is creating 100 objects, syntax may       differ for different languages
}



Hope this helps :)
 
Share this answer
 
v2
Yes you can :
C#
public namespace mynamespace
{
  public class A
  {
    public class B
    {
    }
    public class C
    {
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900