1 / 11

Table of Contents

Table of Contents. Class Objects. Class.

Download Presentation

Table of Contents

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Table of Contents • Class • Objects

  2. Class • In object-oriented programming, a class is a construct that is used as a blueprint to create instances of the class (class instances, class objects, instance objects or just objects). A class defines constituent members which enable 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.

  3. Syntax of Class Class bca { Private : data members; data members; Public: member Functions() { Coding part; } }; // end of class definition Void main() { Class bca b; // b is the object of class bca b. Member functions(); // calling the member functions through object i.e b getch(); }

  4. Access Specifiers • A common set of access specifiers that many object-oriented languages support is: • Private • Public • Protected

  5. Private • The private keyword can be used within a class definition (followed by a colon) to mark subsequent member declarations as private or before a base-class name in the class header to mark the inheritance as private. The default access level of a class is private, both for members and base classes. • Private members can be used by the class itself or by friends. • Private inheritance means all public and protected members in the base class are private to the derived class.

  6. Public • The public keyword can be used within a class definition (followed by a colon) to mark subsequent member declarations as public or before a base-class name in the class header to mark the inheritance as public. The default access level of a struct is public, both for members and base classes. • Public members can be used freely by any other class or function. • Public inheritance means all members of the base class retain their accessibility levels.

  7. Protected • Protected methods and fields can only be accessed within the same class to which the methods and fields belong, within its subclasses, and within classes of the same package, but not from anywhere else. You use the protected access level when it is appropriate for a class's subclasses to have access to the method or field, but not for unrelated classes.

  8. Objects • Objects are the basic run time entities that may represent a person ,place, a bank account and any other thing . • Objects" are the foundation of object-oriented programming, and are fundamental data types in object-oriented programming languages. • In a language where each object is created from a class, an object is called an instance of that class. If each object has a type, two objects with the same class would have the same data type. Creating an instance of a class is sometimes referred to as instantiating the class.

  9. Objects • A real-world example of an object would be “a flying bird", which is an instance of a type (a class) called “Bird“.

  10. Properties of an Object • Identity: the property of an object that distinguishes it from other objects. • State: describes the data stored in the object. • Behavior: describes the methods in the object's interface by which the object can be used.

  11. Properties of an Object • Identity: the property of an object that distinguishes it from other objects. • State: describes the data stored in the object. • Behavior: describes the methods in the object's interface by which the object can be used.

More Related