0% found this document useful (0 votes)
9 views2 pages

Oop Finals Written

The document explains key programming concepts including encapsulation, getters, setters, polymorphism, method overloading, method overriding, interfaces, abstraction, and abstract classes. Encapsulation is used to protect data and control access, while polymorphism allows methods to take on multiple forms. Abstract classes and interfaces serve as blueprints for other classes, promoting code organization and abstraction.

Uploaded by

rbxwmn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Oop Finals Written

The document explains key programming concepts including encapsulation, getters, setters, polymorphism, method overloading, method overriding, interfaces, abstraction, and abstract classes. Encapsulation is used to protect data and control access, while polymorphism allows methods to take on multiple forms. Abstract classes and interfaces serve as blueprints for other classes, promoting code organization and abstraction.

Uploaded by

rbxwmn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Encapsulation Getters

- A getter is a method used to retrieve or "get"


- Encapsulation is a way of keeping things the value of a private variable.
organized in programming. - It provides safe access to the variable without
- It means wrapping the data (variables) and the directly exposing it, which helps maintain
code that works on that data (methods) control over the data.
together in a single unit, called a class.
- It also hides the internal details and allows only
specific parts to be accessed.

Why do we use Encapsulation?

- We use encapsulation to protect important


data and keep things simple.

When do we use Encapsulation?


Polymorphism
- We use encapsulation whenever we need to
- Polymorphism in programming is the ability of
protect data and control how it’s accessed or
a single function, method, or object to take on
modified.
different forms.
- exposing only what’s necessary while keeping
- It comes from the Greek words "poly" (many)
the complex details hidden.
and "morph" (forms), meaning "many forms."
Using Encapsulation - Polymorphism allows a single interface to
represent different types of objects or
- Declare attributes as PRIVATE.
behaviors. This is achieved primarily through
method overriding and method overloading.

Method Overloading

- occurs when multiple methods in the same


class have the same name but different
parameter lists. The difference can be in the
number or type of parameters.
• Happens in the same class.
• Methods differ in their parameters (number, type,
or order).
Setters • Decided at compile time (also called compile-time
polymorphism).
- A setter is a method used to set or update • Return type does not matter for overloading.
the value of a private variable in a class.
- Without a setter, the variable might be
changed to invalid or unexpected values.
Method Overriding
- Method overriding occurs when a subclass provides
a specific implementation for a method that is
already defined in its parent class.
• Happens in different classes (parent and child).
• Both methods must have the same name, parameters,
and return type.
• Decided at runtime (also called runtime polymorphism).
• The method in the child class overrides the method in the
parent class.
INTERFACE

- like a contract or a blueprint that defines what


a class must do, but not how it does it.
- It contains method declarations (without a
body) that the implementing class needs to
provide.
- Interfaces are used to achieve 100%
abstraction and allow multiple classes to follow
the same set of rules.

Key Features of Interface:

1. It is a full Abstract Class that is implemented in


other classes.
Abstraction 2. Any method you declare would be an abstract
- process of hiding unnecessary details and showing method by default, you can use the default
only the essential features of an object or a concept. modifier to create a method with body, also
It helps simplify complex systems by focusing on the method would be static.
what something does, rather than how it does it. 3. Any variable that you declare would be static
1. Abstract Classes (Uses abstract modifier) and final.
2. Interfaces (Uses implements keyword)
Implements Keyword - Used after the class name so
ABSTRACT Class ● It cannot be instantiated because it is that we can implement an interface in that certain
designed to serve as a blueprint or template for other class. Implement interface requires the class to
classes. override every method inside the interface.
ABSTRACT Method ● Can only be declared inside an abstract
class. It is a method without a body and it needs to be
overridden in the subclass of the abstract class

Key Features of Abstract Classes

● Cannot be Instantiated - Abstract classes cannot create


objects directly.

● Can have Abstract Methods - Abstract methods have no


body and must be implemented by subclasses.

● Can have Regular Methods - can include methods with a


body, allowing common functionality to be shared among
subclasses.

You might also like