Definition Declaration of Class Definition of Class In







- Slides: 7
Definition & Declaration of Class
Definition of Class In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as (class instances, class objects, instance objects or just objects). A class defines constituent members which enable these class instances to have state and behavior. Data field members (member variables or instance variables) enable a class object to maintain state. Other kinds of members, especially methods, enable a class object's behavior. Class instances are of the type of the associated class. For example, an instance of the class "Fruit" (a "Fruit" object) would be of the type "Fruit". A class usually represents a noun, such as a person, place or (possibly quite abstract) thing. Programming languages that include classes as a programming construct subtly differ in their support for various class-related features. Most support various forms of class inheritance. Many languages also support advanced encapsulation control features, such as access specifiers
Member accessibility Many languages support the concept of information hiding and encapsulation, typically with access specifiers for class members. Access specifiers specify constraints on who can access which class members. Some access specifiers may also control how classes inherit such constraints. Their primary purpose is to separate the interface of a class from its implementation. A common set of access specifiers that many object-oriented languages support is:
Ø Private (or class-private) restricts the access to the class itself. Only methods that are part of the same class can access private members. Ø Protected (or class-protected) allows the class itself and all its subclasses to access the member. Ø Public means that any code can access the member by its name.
Structure : Along with having an interface, a class contains a description of structure of data stored in the instances of the class. The data is partitioned into attributes (or properties, fields, data members). Going back to the television set example, the myriad attributes, such as size and whether it supports color, together comprise its structure. A class represents the full description of a television, including its attributes (structure) and buttons (interface).
Class bca { Private: Data members_1; Data members_2; Public: Member function_1(); Member function_2(); }; // end of class definition Void main() { Clrscr(); Class bca b; // b is the object of class bca b. Member function_1(); // calling member function_1 b. Member function_2(); getch(); } // calling member function _2
, fields, data members). Going back to the television set example, the myriad attributes, such as size and whether it supports color, together comprise its structure. A class represents the full description of a television, including its attributes (structure) and buttons (interface).