Results 1 to 7 of 7

Thread: Difference between Structure, Classes and Enumeration

  1. #1
    Join Date
    Nov 2009
    Posts
    1,340

    Difference between Structure, Classes and Enumeration

    Hello, I am learning programming languages. Now When I come to know all the details about the Structure, Classes and Enumeration I got confused. If anyone is having detail information about it then please provide me difference between them in simple words. It will be helpful for me to understand.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Difference between Structure, Classes and Enumeration

    If you are making use of the C language then your enum and structure are user defined data type. If you want to make use of them then it is necessary to make use of the enum or struct keyword while using it.
    If you want to define structure in your program then you must need to use the code below:
    Code:
    struct Strct1
    {
    int one;
    char ch;
    }
    For declaring enum in c you may need to use the code below:
    Code:
    enum eone{
          one, two, threee;
    }var;

  3. #3
    softtrickseo Guest

    Re: Difference between Structure, Classes and Enumeration

    Hi,
    according me
    Following are the differences between structure and classes

    1>Structures are value type and Classes are reference type.

    2>Structures can not have constructor or destructor.
    Classes can have both constructor and destructor.

    3>Structures do not support Inheritance, while Classes support Inheritance

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Difference between Structure, Classes and Enumeration

    If you consider the Structures and Enumerations then you will come to know that both of them are of the Value-Types. It will simply tell you that the data of these will be stored on the memory of the stack. But, as Classes are Reference-Types they are stored in the heap memory. As we all know the derivation of the Structures is performed implicitly from the System.ValueType class. It will override the virtual method from the System.Object. If you are allocating any type of the structure then you must need to make use of the new keyword. We can also able to create the constructor for the structure. But, you must need to make the constructor with the parameters. Enum is the keyword used to define an enumeration. Enumeration is consisting of the different constants which are also called as enumerator list. By default Enumeration is of the int type.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Difference between Structure, Classes and Enumeration

    You may need to use the code below to declare the structure:

    Code:
    struct testing 
    {
      public int y,z;
    }
    
    testing test = new testing();
    You may need to use the code below to declare the class:
    Code:
    class test
    {
    int num = 10;
    ...
    }
    You may need to use the code below to declare the emum:

    Code:
    enum colors {red, green, blue, yellow};

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: Difference between Structure, Classes and Enumeration

    Hello, I have learned the C++ and from that I have got the following differences:
    • By default the members of structures are public but in case of the class they are Private.
    • Classes can provide you the facility of the data hiding. But structure wont provide you that.
    • Your structure can provide you only data but class can bind the data with the member functions.

  7. #7
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Difference between Structure, Classes and Enumeration

    We all know that the Structures and Enumerations are Value Types where as classes are the reference types. That is why the data from the structure and enum are stored on the stack and data from the class is stored on the heap. Structures are implicitly derived from a class called System.ValueType. While allocating any structure type we must make use of the new keyword. Parameterless constructor is not allowed in the structure. You can make use of the inheritance in the classes but in structure you cant use it. Enum is the keyword used to define an enumeration. The default underlying type of enum is Integer type.

Similar Threads

  1. Difference between Abstract classes and Interfaces in C#
    By Gallard in forum Software Development
    Replies: 8
    Last Post: 21-05-2012, 11:58 AM
  2. Replies: 3
    Last Post: 04-01-2011, 01:25 AM
  3. What is the difference between Iterator and Enumeration in Java?
    By Karsenman in forum Software Development
    Replies: 4
    Last Post: 28-01-2010, 09:56 AM
  4. Enumeration in C sharp
    By Harper 21 in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 09:52 AM
  5. Confused about difference between structure and union
    By rashmi_ay in forum Software Development
    Replies: 3
    Last Post: 26-11-2009, 01:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,813,650.42167 seconds with 16 queries