OOP Flashcards
What are classes used for?
Blueprints or templates that can be used to create objects within OOP
What is an object?
A representation of a real world entity like a teacher,cat etc
What is instantiation?
Term used for creating an object from a class
What are methods?
Actions or behaviors that can be preformed
What is an identifier?
Name used to refer to an object
What is a function?
Method that must return a value
What is a procedure?
Method that doesn’t need to return a value
What is a constructor?
A special method within a class that is called automatically when an object is created
What do constructors define?
The initial values of instance variables and prepare objects for use
What is a public method?
They are accessible and can be invoked by any code within the same class or any external class
How do changes to a public method affect the rest of the code?
May have an impact on other parts of it so they should be carefully designed
When do we use public methods?
When you want to provide access to certain behaviors of an object or class to other parts of your program
What are private methods?
They are only accessible within the same class and cant be changed by external codes or classes
How do changes to a private method affect the rest of the code?
They have a localised impact since they are only used internally within the class providing flexibility to modify them without affecting the program
When do we use private methods?
When you have internal implementation details that should not be accessed by external code. Only meant to be used within the class itself for organising and managing code internally.
What is inheritance?
When a class inherits the methods and attributes of another class
Why is inheritance good?
Promotes code reuse by allowing the derived class to inherit and utilise the existing code from base class
Avoids duplicating close and promotes better organisation and maintainability
What is encapsulation?
The practice of grouping attributes and methods within a class
Why is encapsulation good?
Ensures that data remains secure and is not accidently modified or misused by controlling access them by using modifiers(public,private)
Helps to organise code keeping related code within an object
Promotes code reusability
Why does encapsulation use abstraction?
Reduces the complexity by hiding implementation details of a project making it easier to understand and work with
What is polymorphism?
A concept in programming that allows objects to take on different forms or behaviors
Why is polymorphism good?
Helps make code more flexible, reusable and easier to maintain
What is overriding ?
Redefining a method within a subclass and altering the code so it functions differently and produces different output
What is overloading?
Passing in different parameters into a method