answersLogoWhite

0

I'm not sure about csharp, but in OO a class has a state and behaviour whereas structure has only state.

The state of a class is the data members, or attributes of a class. Behaviour of a class is the function members, or the methods of a class. Ie, a class has attributes and functions, but a struct has only attributes.

Historically, classes derived from structures. At one point someone thought of adding behaviour or functionality to structures and the resulting type was called a class.

I'll give you an example.

struct Student {
//state
int YearInCollege;
};

This structure has only data members that can be manipulated in the program. Eg:

Student You;
You.YearInCollege=1; //change state
...
int a=You.YearInCollege; //read state

As you can see, we can read and write the members of a structure as we wish.

Now, let's give the structure a bit of functionality.

class Student {
//behaviour
int WhatsMyYearInCollege(void);
void ChangeMyYearInCollege(int);

//state
int YearInCollege;
};

as you can see, now besides the state we also have functionality to change the state of the class. Now, we'll change the state of the class only through its own member functions, also called mutator functions. Eg:

Student You;

You.ChangeMyYearInCollege(2); //change state through class' own function
...
int a=You.WhatsMyYearInCollege(); //read state through class' own function

User Avatar

Wiki User

∙ 17y ago

What else can I help you with?

Related Questions

What is difference between struct variable and class object?

structure variable can access the variable but class object can access the function also


Difference between a class and a struct?

By default, all of the members of a class are private and, by default, all of the members of a structure are public.Structure are value type where as class are reference type.'this' pointer will work only in class.Inheritance between classes is also private by default, and inheritance between structs is public by default.Classes support polymorphism, whereas structure do not.


What's the difference between the Class 365 and Class 465 466?

The difference between the Class 365 and Class 465, 466 is basically the cost.


Difference between exclusive or inclusive class intervals?

difference between inclusive and exclusive class interval


Array is value type or reference type in CSharp?

Array is a class name, hence ought to be a value type.


What is the difference between a class What is the difference between a class III and class IV hitch and?

class III rated for up to 5,000lbs, class IV is rated for up to 10,000lbs towing capacity


What is the difference between abstract class and final class?

20


Difference between Mercedes e class elegance and classic?

What is the difference between Mercedes Benz E class 'Elegance'and classic


What is the difference between structure and class with example?

Structures are public by default whereas classes are private by default. Other than that they are exactly the same. struct s { int num; // s.num is accessible outside of the structure }; class c { int num; // c.num is only accessible to the class itself. };


What is the connection between class structure and economic development?

The answer is the difference between democrates and republicans. Republicans develope so democrates can structure class. The takers (democrates) and the doers (republicans). If allowed the democrates would have us all giving so their "chosen" could have everything and then pitey all of us without.


What is the difference between classes of IP addresses?

difference between ip address and class


What is the Difference between b and c class MS pipe?

The main difference is the thickness of the pipe Compare to A Class pipe B Class pipe thickness is more.Like that Compare to B class pipe C Class pipe thickness is more.

Trending Questions
How can you care for a diskette? Why is that a space charge region in a pn junction at equilibrium is often made small? In C Programming Language Can someone write a program that will interact with the user by name and allow for the recording of grades for three classes Tech History and Math? How does frequency effect op amp? What does the word cistern mean? What is the purpose of heating and air conditioning systems? Where does the energy from coal and beans come from? What is the minimum amount of light that must enter a living space? Does your supervisor cooperate with you in the fulfillment of your responsibilities? How do you measure transient voltage? Is mechanical engineering field specialized? What is the resistance of a bulb that uses an average power of 75 W when connected to a 60 Hz power source with a peak voltage of 170V? The processes list by technology to improved material? What are the three interpretations for null values? What action must be taken with eeds before performing an electrical continuity electrical repair or resistance check on an explosive facility? What are the problems associated with carrying out modifications on mechanical assemblies and why is it important to inform the appropriate people of non-conformances? Why are pipes in a heating system insulated? What happens to the brightness of the bulb when the second bulb is put into a series circuit? What are some engineers that start with A-Z? What resistance does a light bulb have?