Difference between Class and Struct.
Answers were Sorted based on User's Feedback
The only difference between a struct and a class is in the
default access. By default, all the members of a struct are
public whereas in a class, al the members are private. The
same is true for the default inheritance type: a struct
entails public inheritance by default whereas a class
entails private inheritance.
Is This Answer Correct ? | 98 Yes | 23 No |
Answer / praveena.g
class ex:-
class classname
{
int a;
float b;
}
struct {
int a;
int b;
}struct name;
in the struct all members are by default public,
in the class we can deference it private,public,protected.
like these we class will taken.
Is This Answer Correct ? | 62 Yes | 19 No |
Answer / ajay prajapat
1. Structure is value type where is class is refrance
type.So class data is store in heap where as stuct data are
store in stack.
2. default type of function in struct is public where as
private in class
Is This Answer Correct ? | 55 Yes | 15 No |
Answer / kishore
What is the difference between class and structure?
1) Structure: Initially (in C) a structure was used to
bundle different type of data types together to perform a
particular functionality. But C++ extended the structure to
contain functions also. The major difference is that all
declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all
the members inside the class are private.
2) structures in c++ doesn't provide data hiding where as a
class provides data hiding
classes support polymorphism, whereas structures don't
3) class and structure are very similar. the former is
heavyweight while the latter is light weight. reference to
the former rests on the heap..while the latter in whole
(instance and data) rests on the stack. therefor care
should be taken not to make a struct very heavy else it
overloads the stack causing memory hogging. class needs to
have an instance explicitly created to be used. A struct
doesn't have to be explicitly initiated
Is This Answer Correct ? | 44 Yes | 7 No |
Answer / jammu hari (v.v. narasimharao
Difference between class & Structure is :-
-------------------------------------------
1. class = data + functions
structure=Collection of different data
2. Class supports Re-usability. Structures are used to handle
the complex data.
3. Both are user defined data types.
4. 'struct' is a keyword which is used to declare a structure.
'class' is a keyword used to declare a class.
5. By default all the structure members are public. But in
class all the members are private.
6. Structure variable is used to access the structure
members. Object is used to access the class members.
7. Structure is less secure than the class.
8. Structure is a procedure Oriented feature. Object is a
Object Oriented Feature.
9. Both Structure & Class uses (.) dot operator to access
their members.
10. class contains 3 access specifiers But structure has
only 1 access specifier.
11. We can inherit a class. But we can't inherit structure.
12. We can declare constructors & destructors inside of a
class. But we can't declare these in Structure.
13. Structure are not suitable of Data Hiding. But classes
well suited for data hiding.
14. Structure is a valute type. Class is a reference type.
so, class data is stored in heap & structure data is
stored in stack.
15. class is an extension to the structure.
16. structures are used to handle the complex data.
class is used for reusability.
Is This Answer Correct ? | 41 Yes | 14 No |
Answer / jammu hari cell:9848278041
Difference between class & Structure is :-
-------------------------------------------
1. class = data + functions
structure=Collection of different data
2. Class supports Re-usability. Structures are used to handle
the complex data.
3. Both are user defined data types.
4. 'struct' is a keyword which is used to declare a structure.
'class' is a keyword used to declare a class.
5. By default all the structure members are public. But in
class all the members are private.
6. Structure variable is used to access the structure
members. Object is used to access the class members.
7. Structure is less secure than the class.
8. Structure is a procedure Oriented feature. Object is a
Object Oriented Feature.
9. Both Structure & Class uses (.) dot operator to access
their members.
10. class contains 3 access specifiers But structure has
only 1 access specifier.
11. We can inherit a class. But we can't inherit structure.
12. We can declare constructors & destructors inside of a
class. But we can't declare these in Structure.
Is This Answer Correct ? | 20 Yes | 8 No |
Answer / rahul yadav
wrong
structs can also contain functions in C++,
but in C, i ma not sure.
but since we are talking abot Class so we have to answer in
the context of C++,hence the answer is wrong.
only diff is of default variable scope.
Is This Answer Correct ? | 37 Yes | 27 No |
Answer / naresh kukreti
The struct default access type is public. A struct should
typically be used for grouping data.
The class default access type is private, and the default
mode for inheritance is private. A class should be used for
grouping data and methods that operate on that data.
In short, the convention is to use struct when the purpose
is to group data, and use classes when we require data
abstraction and, perhaps inheritance.
In C++ structures and classes are passed by value, unless
explicitly de-referenced. In other languages classes and
structures may have distinct semantics - ie. objects
(instances of classes) may be passed by reference and
structures may be passed by value.
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / naresh kukreti
1)measure difference between structure and class is that
the structure doesn't inherit but class is inherit
2)by default the data members of structure are public but in
case of class data members are private
3) Class is much secure ,but structure is not secure
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / frozan maqsoodi
the main difference is the default access specifier.
constructors can be declared in structures. try it, you
will get the answer.
Is This Answer Correct ? | 1 Yes | 0 No |
If one always ought to act so as to produce the best possible circumstances, then morality is extremely demanding. No one could plausibly claim to have met the requirements of this "simple principle." . . . It would seem strange to punish those intending to do good by sentencing them to an impossible task. Also, if the standards of right conduct are as extreme as they seem, then they will preclude the personal projects that humans find most fulfilling. From an analytic perspective, the potential extreme demands of morality are not a "problem." A theory of morality is no less valid simply because it asks great sacrifices. In fact, it is difficult to imagine what kind of constraints could be put on our ethical projects. Shouldn't we reflect on our base prejudices, and not allow them to provide boundaries for our moral reasoning? Thus, it is tempting to simply dismiss the objections to the simple principle. However, in Demands of Morality, Liam Murphy takes these objections seriously for at least two distinct reasons. First, discussion of the simple principle provides an excellent vehicle for a discussion of morality in general. Perhaps, in a way, this is Murphy's attempt at doing philosophy "from the inside out.". . . Second, Murphy's starting point tells us about the nature of his project. Murphy must take seriously the collisions between moral philosophy and our intuitive sense of right and wrong. He [must do so] because his work is best interpreted as intended to forge moral principles from our firm beliefs, and not to proscribe beliefs given a set of moral principles. [Murphy] argues from our considered judgments rather than to them. . . For example, Murphy cites our "simple but firmly held" beliefs as supporting the potency of the over-demandingness objection, and nowhere in the work can one find a source of moral values divorced from human preferences. Murphy does not tell us what set of "firm beliefs" we ought to have. Rather, he speaks to an audience of well-intentioned but unorganized moral realists, and tries to give them principles that represent their considered moral judgments. Murphy starts with this base sense of right and wrong, but recognizes that it needs to be supplemented by reason where our intuitions are confused or conflicting. Perhaps Murphy is looking for the best interpretation of our convictions, the same way certain legal scholars try to find the best interpretation of our Constitution. This approach has disadvantages. Primarily, Murphy's arguments, even if successful, do not provide the kind of motivating force for which moral philosophy has traditionally searched. His work assumes and argues in terms of an inner sense of morality, and his project seeks to deepen that sense. Of course, it is quite possible that the moral viewpoints of humans will not converge, and some humans have no moral sense at all. Thus, it is very easy for the moral skeptic to point out a lack of justification and ignore the entire work. On the other hand, Murphy's choice of a starting point avoids many of the problems of moral philosophy. Justifying the content of moral principles and granting a motivating force to those principles is an extraordinary task. It would be unrealistic to expect all discussions of moral philosophy to derive such justifications. Projects that attempt such a derivation have value, but they are hard pressed to produce logical consequences for everyday life. In the end, Murphy's strategy may have more practical effect than its first-principle counterparts, which do not seem any more likely to convince those that would reject Murphy's premises. 1) The author suggests that the application of Murphy's philosophy to the situations of two different groups: a) would help to solve the problems of one group but not of the other. b) could result in the derivation of two radically different moral principles. c) would be contingent on the two groups sharing the same fundamental beliefs. d) could reconcile any differences between the two groups. 2) Suppose an individual who firmly believes in keeping promises has promised to return a weapon to a person she knows to be extremely dangerous. According to Murphy, which of the following, if true, would WEAKEN the notion that she should return the weapon? a) She also firmly believes that it is morally wrong to assist in any way in a potentially violent act. b) She believes herself to be well-intentioned in matters of right and wrong. c) The belief that one should keep promises is shared by most members of her community. d) She derived her moral beliefs from first-principle ethical philosophy. 3) The passage implies that a moral principle derived from applying Murphy's philosophy to a particular group would be applicable to another group if: a) the first group recommended the principle to the second group. b) the moral viewpoints of the two groups do not converge. c) the members of the second group have no firmly held beliefs. d) the second group shares the same fundamental beliefs as the first group. 4) According to the passage, the existence of individuals who entirely lack a moral sense: a) confirms the notion that moral principles should be derived from the considered judgments of individuals. b) suggests a potential disadvantage of Murphy's philosophical approach. c) supports Murphy's belief that reason is necessary in cases in which intuitions are conflicting or confused. d) proves that first-principle strategies of ethical theorizing will have no more influence over the behavior of individuals than will Murphy's philosophical approach. 5) Which of the following can be inferred about "doing philosophy from the inside out?" a) Murphy was the first philosopher to employ such an approach. b) It allows no place for rational argument in the formation of ethical principles. c) It is fundamentally different from the practice of first-principle philosophy. d) It is designed to dismiss objections to the "simple principle." 6) A school board is debating whether or not to institute a dress code for the school's students. According to Murphy, the best way to come to an ethical decision would be to: a) consult the fundamental beliefs of the board members. b) analyze the results of dress codes instituted at other schools. c) survey the students as to whether or not they would prefer a dress code. d) determine whether or note a dress code has ever been instituted in the school's history
Explain setjmp()?
What is class and object in c?
what is difference between #include<stdio.h> and #include"stdio.h"
What is Lazy evaluation in C? Give an example.
An array name contains base address of the array. Can we change the base address of the array?
What are bit fields? What is their use?
What is the function of this pointer?
0 Answers Agilent, ZS Associates,
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
write a program that will read the temperature in Celsius and convert that into Fahrenheit.
what is c
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)