4 and Programming Flashcards

(27 cards)

1
Q

Objects

A

Objects are the fundamental building blocks of object-oriented programming (OOP). They represent real-world entities or abstract concepts in code. An object encapsulates data (attributes) and the methods that operate on that data.

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

Classes

A

A class is a template or blueprint for creating objects. It defines the attributes and methods that all objects of that type will have.

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

Instantiation

A

Instantiation is creating an object.
And each object is an instance of its class.

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

Encapsulation

A

Encapsulation is like creating a protective capsule around an object’s internal data, shielding it from unauthorized access and manipulation. It involves:
* Data hiding: Making an object’s internal data private
* Public interfaces: Providing controlled access to the object’s data through methods

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

Association

A

This is a general relationship between objects. For example, a Student object might be associated with multiple Course objects.

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

Aggregation

A

This is a “has-a” relationship where one object contains references to other objects. For instance, a University object might contain multiple Department objects.

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

Composition

A

This is a stronger form of aggregation where the contained objects cannot exist independently of the container. For example, a House object might be composed of Room objects.

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

Inheritance

A

This is an “is-a” relationship where one class (subclass) inherits properties and methods from another class (superclass). For example, a Car class might inherit from a Vehicle class.

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

Object-Oriented Design Process

A
  • Identifying the objects in the system
  • Defining the attributes for each object
  • Determining the methods each object should have
  • Establishing the relationships between objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Benefits of Object-Oriented Programming

A
  • Modularity: Objects can be maintained independently of other objects or code. Allowing coding teams to divide the work
  • Reusability: Objects can be reused in different programs. Plus inheritance.
  • Productivity: Programmers can build new programs quicker through the use of existing objects.
  • Easily upgradable and scalable: Updating or adding new features becomes easier.
  • Security: The encapsulation of data and functionality provides a secure programming model.
  • Flexibility: Through polymorphism, objects can be treated as instances of their parent class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Advantages of Encapsulation

A
  • Data Protection: Prevents unauthorized access to an object’s internal state.
  • Flexibility: Allows changing the internal implementation without affecting the public interface.
  • Maintainability: Easier to debug and maintain as data access is controlled.
  • Modularity: Promotes modular design by separating internal workings from external interactions.
  • Prevents accidental data editing from other classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Parent-child relationship in inheritance.

A
  • Parent class (superclass): The existing class being inherited from
  • Child class (subclass): The new class that inherits from the parent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Advantages of Inheritance

A
  • Code Reusability: Reduces redundancy by reusing code from existing classes.
  • Hierarchical Classification: Organizes classes into a logical hierarchy.
  • Extensibility: Easily extend or specialize existing classes.
  • Polymorphism: Enables runtime polymorphism through method overriding.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Polymorphism

A

Polymorphism allows methods to have the same name and only be differentiated by the class they are in or the parameters they have.

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

Types of Polymorphism

A
  • Compile-time Polymorphism (Method Overloading): Multiple methods with the same name but different parameters in the same class.
  • Runtime Polymorphism (Method Overriding): Subclass provides a specific implementation for a method defined in its superclass.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Attributes

A

Data to create object

17
Q

Methods

18
Q

UML Diagrams

A

Unified Modeling Language (UML) diagrams are visual representations of software systems. They help in designing, documenting, and communicating about object-oriented systems.

19
Q

Recursion

A

Recursion occurs when a method calls itself within its own code. This self-referential approach allows complex problems to be solved by repeatedly applying the same solution to smaller instances of the problem.

20
Q

Key Components of Recursion

A
  • Base case: The condition that stops the recursion
  • Recursive case: The part where the function calls itself
  • Progress towards the base case: Each recursive call should move closer to the base case
21
Q

Tracing Recursive Algorithms

A

Tracing recursive algorithms involves following the sequence of recursive calls and their return values.

22
Q

Floating-point numbers

A

Decimals (Doubles)

23
Q

Issue with doubles

A

Take more memory

24
Q

A disadvantage of using Object Oriented Design.

A

To construct an Object Oriented program is difficult and for many smaller tasks potentially unnecessary.

25
Advantages of using Object Oriented Design.
* Allows a team to divide a job up into a number of smaller tasks. For example, each member of the team could work on an individual object (e.g. one could work on the Bus object, whilst the other works on BusRoute). * Code Reusability: OOP promotes code reusability through inheritance, where new classes can inherit properties and methods from existing classes, reducing the need for repetitive code
26
How to initiate an Array?
DataType[] name = new DataType[x]; Where DataType can be any primitive or object class and x is the array's size.
27
Parameters
Data entered to a method. Example: setDriver(**String Driver**)