OOP Flashcards

1
Q

What does a getter do?

A

It gets the value attributes of a class

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

What does a setter do?

A

It sets the value of a class

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

What does a constructor do?

A

It forces attributes on creation of an object of the class.

(method that is ran when an object is instantiated)

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

What is method overloading?

A

Same method but different parameter or data type

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

What is constructor overloading?

A

Normal overloading but with multiple contstructors instead of methods.

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

What is method overriding

A

It is basically updating an already existing function

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

How to use inheritance in Java?

A

Public class Lowerclass extends Superclass

and
in constructor
super(variable name)

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

What does adding abstact to a class do?

A
  1. The class cannot be instantiated( meaning you cant make an object from the class, but they can have sub classes which you can instantiate ( make an object)

Polymorphism

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

What does adding abstract to a method do?

A

It means that the method doesnt have a body (no code)
So you must use it in a subclass.

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

What is the difference between a singly, doubly and circularly linked list.

A

Singly: normal
Doubly: has next and previous
Circularly: The tail is connected to the head (the tail points to the head.

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

How to overload methods?

A

Same method name but different data type or different no. of parameters

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

How to override methods?

A

You type @Override
then give the method in the sub class new code.

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

What does super keyword do?

A

Super refers to the subclass’s super class (similar to .this)

attributes:
super(values to be passed from the superclass);
this.value in the sub class
methods:
super.methodname();

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

How to use encapsulation?

A

Use getter and setter

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

How to code encapsulation?

A

When creating the object from the class, you have to use the getter and setter methods instead of objectName.variableName

The constructor will also use the setter to give values.

Use private and protected

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

What is polymorphism

A

Basically method overiding or overloading (u can use both) with multiple different classes that inherit from the same superclass.

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

How to do exceptions?

A

Try = Code to test
Catch = Code to run if theres an error

catch(Exception e) {}

(add more types of catch exceptions for different type of errors or just put exception)
Finally = Code to run after the try and catch
Throw new = Makes an error happen (you have to give the error type)

18
Q

What is an Array

A

An array is a data structure, which can store a fixed-size collection of elements of the same data type.

19
Q

What is the syntax in Java for creating a 2D array?

A

int [ ] [ ] arrayName = new int [ 3 ] [ 3 ];

OR

int [ ] [ ] arrayName =
{

{1,2,3},
{4,5,6},
{7,8,9}

};

19
Q

How to traverse in 2D arrays in Java

A

for ( int i = 0; i < arrayName.length; i++) {

for (int j = 0; j < arrayName[i].length; i++) {

System.out.println(arrayName[ i ] [ j ]

19
Q

What is a 2D array?

A

A 2D array is an array of arrays, where each element is itself an array. It is a collection of
elements arranged in rows and columns.

20
Q

What are 2 uses of 2D arrays?

A

2D arrays are useful for representing matrices or grids.

20
Q

What is a linked list?

A

A linked list is a linear data structure where elements are not stored contiguously in memory.
Instead, each element (node) contains a value and a reference to the next node in the
sequence.

20
Q

What are the 3 types of linked lists?

A

singly linked, doubly linked, and circular linked lists.

20
Q

What are the main methods for linked lists?

A

insert, delete, display. delete, replace, inserting at a given position

20
Q

What are stacks?

A

A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle

Stacks can be implemented using arrays or linked lists.

20
Q

What are 4 uses of stacks

A

Stacks are used in various applications, such as expression evaluation, backtracking
algorithms, and undo/redo operations.

21
Q

What are the main methods used for stacks?

A

Push, pop, is Empty, peek, size

21
Q

What are Queues?

A

A queue is a data structure that follows the First In, First Out (FIFO) principle. It’s similar to standing in a line or queue at a store, where the first person to join the line is the first to be served.

22
Q

What are 3 uses of queues?

A

Queues are commonly used in various computer algorithms and applications, such as job scheduling, task management, and breadth-first search algorithms.

22
Q

What are the 4 types of queues?

A

Linear Queue, Circular Queue, Priority Queue
and Delay Queue.

23
Q

What is a Linear Queue?

A

In a linear queue, elements are arranged in a linear or sequential manner. It follows the FIFO (First In, First Out) principle, where elements are inserted at one end (rear) and removed from the other end (front).

24
Q

What is a Circular Queue?

A

Circular queues are similar to linear queues, but they wrap around when reaching the end of the underlying array or buffer. This allows efficient use of space and prevents wastage. Circular queues have a fixed size and offer better performance for certain applications like buffering in I/O operations.

25
Q

What is a Priority Queue?

A

Priority queues are a type of queue where each element has an associated priority. Elements with higher priority are dequeued before those with lower priority, regardless of the order they were added. Priority queues are commonly used in algorithms like Dijkstra’s shortest path algorithm and in scheduling tasks.

26
Q

What is a Delay Queue?

A

A delay queue holds elements until a certain delay has elapsed before allowing them to be dequeued. Elements are ordered based on their delay duration.

27
Q

What is Encapsulation?

A

Encapsulation helps in achieving data hiding and protects the integrity of the data by preventing direct access from outside the class

Security

28
Q

What is Abstraction

A

Abstraction is like using a TV remote without knowing how it works internally. It allows you to focus on what an object does, rather than how it does it. You deal with the essential characteristics of an object, ignoring the unnecessary details.

Abstraction, on the other hand, focuses on hiding the implementation details of an object and emphasizing only the essential features or behaviors relevant to the interaction with the object. It allows us to work with high-level concepts without worrying about the low-level details of how those concepts are implemented.

encapsulation sets boundaries and controls access to the inner workings

29
Q

What is Inheritance?

A

Inheritance is like passing down traits from parents to children. It allows a new class to inherit properties and behaviors from an existing class, promoting code reusability and facilitating hierarchical relationships.

30
Q

What is Runtime Polymorphism

A

Method overriding

31
Q

What is