Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 498595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:53:58+00:00 2026-05-13T05:53:58+00:00

What is real difference between Class and Structure when you are dealing with Object

  • 0

What is real difference between Class and Structure when you are dealing with Object Oriented Programming. This question is asked many times during my interviews for SE.

Some people says that there is only one difference:
Structure members are public by default and Class members are private by default.

Some says there are many differences.

After reading many articles and forums, I have the following differences:

Classes DEFAULT to having private members. Structures DEFAULT to having public members.

Structures are values type.
Classes are reference type.

Structure stores in memory via stack.
Classes stored in memory via heap.

Structure doesn’t support inheritance.
Classes support inheritance.

Constructor works in different way.

‘new’ operator works in different way.

Allocating memory for structure is very fast because this takes place inline or on the stack.

What are your opinion on my above list or you have a different one. Thanks

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:53:58+00:00Added an answer on May 13, 2026 at 5:53 am

    This is pretty language-specific. You seem to be mixing a fair share of both C++ and C#, both of which are very different languages (despite superficial similarities in syntax).

    In C++ structs indeed default to public member visibility while class defaults to private. In C# struct is used to declare value types which are passed by value (note that the stack allocation is an implementation detail, not a contract).

    Generally both languages seem to have the same idea of what struct and class should represent: struct is for simple data structures which do little more than holding data, while classes have state and methods to manipulate it. They are used to build objects in some concrete or abstract sense while data structures are just that: data in a structured form; they don’t need to do much with that data or even know what data that is. Essentially they’re dumb and don’t care.

    But that’s just how the language designers thought they should be used. People are good at mis-using things so not every struct you see may be a simple, dumb data structure and not every class you see may be a full-blown class with lots of methods and whatnot. It’s merely a convention and if people follow it others can look at the code and see “Oh, nice, that’s a struct so I don’t expect much logic here and move on to more interesting things.” It might work … in theory.

    ETA: Since you mentioned in a comment that you are particularly interested in PHP or Java: Both languages do not have any distinction at the syntax or language level of class or struct which is why your question strikes me as a little odd. In both Java and PHP you model things as classes, regardless of whether they are just data structures without logic or actual classes with everything there is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any real difference between: id value; BOOL compare1 = [value isMemberOfClass:[SomeClass class]];
For the sake of this question, I don't care about the difference between stubs,
What real (i.e. practical) difference exists between a static class and a singleton pattern?
What is the real difference between a C# static constructor and a Java static
Real noob question no doubt, but I can't get my head around this behaviour.
I don't know what real difference between two type of using when I want
I am learning Threading and I am bit confused, what the real difference between
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
After reading a question on the difference between pointers and references , I decided
Possible Duplicate: PHP: What is the difference between an interface and abstract class? As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.