OOP Flashcards

1
Q

Abstraction

A

Using simple things to represent complex concepts. (e.g: wrapping a complex algorithm in a class, so the caller can just get the result without worry about what is involved in generating it)

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

Encapsulation

A

Protecting objects from external modification by offering a well defined public interface for consumers to work with (e.g: class variables are hidden and can only be accessed by getters/setters and methods)

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

Inheritance

A

Allows class to use the properties/methods of another class, child(subclass)-parent(superclass), java use ‘extends’ [is-a relationship]
public class Cat extends Animal{}

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

Polymorphism

A

Many forms, compile time (overloading - static) and run time (overriding - dynamic)

A conceptual example is a class of Type Horse extends a class called Animal. Both classes implement a method move(). If an instance of Horse is created and stored in an Animal variable then when we invoke animal.move() it will use the horse’s implementation of move not the Animals.

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

Inheritance vs Composition

A

Is a vs has a

Tightly coupled vs loosely coupled

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

Composition

A

Instance variable of another object [has-a relationship]
public class Person {
private Job job; //composition has-a relationship
}

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

Abstract Class

A

Cannot be instantiated, must be inherited, can have both abstract/regular methods, abstract methods don’t have a body

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

Interface

A

Contract with a set of methods that a class must implement, class can implement multiple interfaces, member variables are final by default

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

Overloading

A

Same named methods with different arguments

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

Overriding

A

Overriding a method from its parent class with different behavior

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

Multithreading

A

Small unit of work in parallel, multiple threads concurrently, maximize cpu

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

Deadlock

A

Threads blocked waiting on eachother

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

Synchronization

A

Only 1 thread can execute at a time

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

Checked Exceptions

A

IO or compile time, must be caught or program will not compile
Unchecked Exceptions - runtime or null pointer, program will run without catching them

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

Unchecked Exceptions

A

Runtime or null pointer, program will run without catching them

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

Chained Exceptions

A

One exception causes another exception

17
Q

Class

A

blueprint/template, encapsulates data for the object
public class Class {
// fields or member variables
// constructor
// methods (defines behaviors or operations)
// getters/setters (access and modifiers)
// equals (default compares memory addresses, override to compare contents - when storing in collections like HashMap/HashSet this ensures duplicate objects are handled)
// hashcode (returns int value represents the object within a collection that uses hashing HashMap/HashSet)
// toString (string representation of the object, default is hex of hashcode)
}

18
Q

Objects

A

Instance of a class

19
Q

Garbage Collection

A

Program on JVM to delete unused objects, automatic memory management

20
Q

Memory Leaks

A

Places where memory is not reclaimed when the object isn’t being used anymore

21
Q

Primitive Type

A

byte,short,int,long,char,double,boolean (literals)

22
Q

Wrapper Class

A

Byte,Short,Int,Long,Character ,Double,Boolean (Objects)

23
Q

Immutable

A

Final, value of object is modified, a new object must be created

24
Q

Autoboxing

A

auto converts primitive to wrapper class object when used in a collection

25
Q

Unboxing

A

Auto converts wrapper class to primitive

26
Q

Problem with Boxing/Unboxing

A

Overhead for garbage collector (conversion from value types to reference types (objects) introduce additional memory management.

When a int is boxed, it is wrapped in an object and stored on the heap instead of the stack. Heap allocations are managed by the GC. GC is responsible for tracking & eventually cleaning them up.

27
Q

Static Variable/Method

A

Belongs to the class, can be called without creating an instance

28
Q

Final Variable

A

Cannot be changed, constant

29
Q

Final Method

A

Cannot be overridden

30
Q

Final Class

A

Cannot be inherited

31
Q

What are the access modifiers?

A

Private - only accessed in the class
Protected - only accessed in the class and subclasses
Public - accessed from anywhere

32
Q

Diamond Problem

A

Ambiguity that arises from two classes B/C inherit from a superclass A, and another class D inherits from B/C, this is why you can’t extend multiple abstract classes