Object Orientated Programming Flashcards

(13 cards)

1
Q

What are classes?

A
  • Classes are used as blueprints or templates that can be used to create objects in OOP
  • This method allows for reusable and organised code in a modular way
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are objects?

A
  • An object is a representation of a real world entity
  • A class is a blueprint that describes the properties and behaviours of objects, while an object is a specific instance created using the blueprint
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are constructors?

A
  • A special method within a class that is automatically called when an object of that class is instantiated (created)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is a class set up called ItemForSale with 3 attributes: itemName, price, discount

A

class ItemForSale
private itemName
private price
private discount

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to add a new object to a class ItemForSale with 3 attributes

A

public procedure new (givenItemName, givenPrice, givenDiscount)
itemName = givenItemName
price = givenPrice
discount = givenDiscount
endprocedure

tank = ItemForSale new (“tank”, 20, 5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a method and what are the 2 different types?

A
  • A method is a function that is associated with objects or classes that define the behaviour and actions that an object can perform
  • The two types are functions and procedures
  • Functions: performs a task and returns a value
  • Procedure: performs a task but doesn’t return a value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe a public method

A
  • Accessible and can be invoked by any code within the same class or from any external classes
  • Changes to public methods may effect other parts of the code
  • Used when you want to provide accessibility of certain functionalities of an object or class to other parts of your program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe a private method

A
  • Only accessed within the same class and cannot be invoked by external code or other classes
  • Changes to private methods have a localised effect
  • Used when you have internal implementation details that should not be accessed or used by external code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an attribute?

A
  • Refers to a data memory or a property associated with an object or class
  • They define the state of an object and can have different values for different instances of the same class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is inheritence?

A
  • Allows a class to inherit the properties and behaviours of another class
  • Allows a derived class to inherit and utilise existing code from the base class
  • The derived class “is a” base class
  • E.G: the base class is vehicle and derived class is car. A car “is a” vehicle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is encapsulation?

A
  • The practice of grouping data (attributes) and methods (functions) within a class
  • Using encapsulation ensures that data remains secure and is not accidentally modified or misused by controlling access to them using access modifiers (public, private)
  • It also helps to organise code by keeping related methods and data together
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is abstraction in encapsulation?

A
  • Reduces complexity by hiding the implementation details of the object, making it easier to work with and understand
  • Programmers can use methods and classes from other parts of the program without having to understand how they are constructed internally
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is polymorphism?

A
  • Allows objects to take on different forms or behaviours
  • Different objects can share the same name or behaviour but can work in different ways
  • It helps make code more flexible, reusable and easier to manage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly