ACCESS MODIFIERS
Access modifiers define the boundaries up to which an object or a variable can be accessed within a project.
Based on its area of access, it can be classified into four types.
Namely:
1. PUBLIC
2. PRIVATE
3. PROTECTED
4. DEFAULT
1. PUBLIC:
The public keyword allows a variable or an object to be accessed anywhere throughout the project.
2. PRIVATE:
The private keyword allows a variable or an object to be accessed only within the class it has been declared.
3. PROTECTED
The protected keyword allows a variable or an object to be accessed only within the package it was declared, even if it has been extended.
4. DEFAULT
The default keyword allows a variable or an object to be accessed only within the package it was declared, but if it has been extended, we can use it in another package.
POLYMORPHISM
Polymorphism refers to accessing a single method with different data types for different purposes.
They are classified into two types based on their usage. They are:
1. Overloading
2. Overriding
1. Overloading
Overloading refers to the process of using the same method name with different types of arguments or numbers of arguments. This is referred to as compile-time polymorphism because decisions are made during compile time.
2. Overriding
Overriding refers to the process of using the same method name in a different class used for a different purpose. This is referred to as run-time polymorphism because decisions are made during run time.
SWITCH CASE:#
Switch case is a conditional statement that has a user-defined number of cases that can be accessed by passing arguments. The prevailing break statement that was mandatory was replaced with '->'.
IMPORT:
Import is used to access a class from another package.
'import package.class;' is the syntax to import a single class from another package.
'import package.*;' is the syntax to import all the classes from another package.
Top comments (0)