محاضرة 4
Classes and Objects
مبدأ البرمجة كائنية التوجه، الكلاسات، والـ Objects.
يلا نشوف الملخص
📖 Lecture 4: Methods and Scope
- Methods: Blocks of code that run only when called, used to reuse code [14]. They are defined with parameters (inputs) and a return type (or
voidif they return nothing) [15, 16].- When passing primitive variables to a method, a copy is passed. Changes inside the method do not affect the original variable [17].
- Variable Arguments (Varargs): Written as
int... a, allowing a method to accept an arbitrary number of arguments. It must be the last parameter in the method signature [17].
- Method Overloading: Creating multiple methods with the same name but different parameters (type or count) inside the same class [18].
- Access Modifiers:
public(accessible anywhere),private(accessible only inside the same class),protected(same package and subclasses), and default (same package only) [15].
- Non-Access Modifiers:
static: Belongs to the class, can be called without creating an object [15, 17].final: Cannot be overridden [15].abstract: Declared but not implemented [15].
- Scope: Variables are only accessible inside the region (block
{}) where they are created [17]. - Recursion: A method calling itself to solve smaller instances of a problem (e.g., calculating powers) [19, 20].
في نقطة مش واضحة؟ بطبط موجود!
اسأل بطبط عنها