This post might just be a little technical. It is dedicated to all those who are going for an interview. This is a very common question so let me just share whatever I know of classes.
Most languages offer primitive data types like int, long and float. Their data representation and response to arithmetic, assignment and relational operators are defined as part of the language. However, the language does not know user-defined data types. The programmer defines its format and behaviour by defining a class. For example, there can be a user-defined data type to represent dates. The compiler and the computer do not know about dates. Programmers have to define the behaviour of dates by designing a date class. This class expresses the format of date and the operations that can be performed on it. The way we can declare many variables of the primitive type int, we can define many objects of the date class. A class serves as a blueprint or a plan or a template. It specifies what data and what functions will be included in objects of that class. Defining the class does not create any objects, just as the mere existence of a type int does not create any variables.
Most languages offer primitive data types like int, long and float. Their data representation and response to arithmetic, assignment and relational operators are defined as part of the language. However, the language does not know user-defined data types. The programmer defines its format and behaviour by defining a class. For example, there can be a user-defined data type to represent dates. The compiler and the computer do not know about dates. Programmers have to define the behaviour of dates by designing a date class. This class expresses the format of date and the operations that can be performed on it. The way we can declare many variables of the primitive type int, we can define many objects of the date class. A class serves as a blueprint or a plan or a template. It specifies what data and what functions will be included in objects of that class. Defining the class does not create any objects, just as the mere existence of a type int does not create any variables.
No comments:
Post a Comment