Object-Oriented-Programming-OOP
Object-Oriented-Programming-OOP
Programming (OOP)
Welcome to the world of Object-Oriented Programming (OOP)! In this
presentation, we'll delve into the concepts of instance and class fields,
exploring how they define the characteristics and behaviors of objects within
a class. We'll also learn how to create, initialize, and display these fields using
objects.
AM by Abdul Malik
Understanding Instance and
Class Fields
1 In-Line Initialization
Assign values to instance fields directly within the class
definition, when the field is declared.
2 Constructor Initialization
Use the constructor of the class to assign values to instance
fields when an object is created.
3 Method Initialization
Initialize instance fields within methods of the class,
providing flexibility based on specific conditions or
calculations.
Accessing Instance Fields
Within the Same Class From Other Classes Visibility Restrictions
Directly access instance fields using the Access instance fields of an object from Access modifiers control the visibility of
dot operator (.) within the same class other classes using the object reference instance fields, restricting access based
where they are defined. and the dot operator. on the modifier used (e.g., public,
private).
Defining Class Fields
Data Type Field Name Access Modifiers
Each class field must be declared with Choose meaningful and descriptive Access modifiers control the visibility
a specific data type, such as int, names for class fields to clearly of class fields. Options include public,
string, or boolean, to determine the identify their purpose within the private, protected, and internal.
kind of data it can hold. class.
Initializing Class Fields
1 In-Line Initialization
Assign values to class fields directly within the class
definition, when the field is declared.
3 Method Initialization
Initialize class fields within static methods of the class,
providing flexibility based on specific conditions or
calculations.
Accessing Class Fields
Within the Same Class From Other Classes Visibility Restrictions
Directly access class fields using the Access class fields of a class from other Access modifiers control the visibility of
class name and the dot operator (.) classes using the class name and the dot class fields, restricting access based on
within the same class where they are operator. the modifier used (e.g., public, private).
defined.
Creating Objects and
Initializing Fields
Object Creation
3 Access and modify class fields using the class name and the
dot operator, as they are shared across all objects.
Displaying Field Values
Field Type Access Method Output Example