OOP Flashcards

1
Q

what is oop

A

= a programming methodology centered around the concepts of classes and objts
used to transfer a model of the rw > sw.

Why? to simplify dev and maintainance.

eg: pet main system for dogs.

what is design process?

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

what is a class

A

a class is a blueprint from which individual objts are created.

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

what is a object

A

any thing that has a state and behavior.

eg-car

state(attritubutes)

-make, model, size

behavior
- move, reverse, turn

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

what are advantages of oop over procedure

A

dev and maint easier. > as complexity increases

hides data whereas procedural allows global.

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

what is a constructor

A

a code block similar to a method.

used to initialized the object.

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

when is a constructor called

A

when an object is created. it constructs the value at that time.

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

what are the rules for creating a constructor

A
3
name = class name
no explicit return type
cant be FASS final, abstract, synchronized, static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what are the types of constructors

A

2
default = compiler creates w/o parameter
parameterized = has parameter when created

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

constructor overloading

A

a technique of having more than 1 constructor w/ diff parameter lists.
arranged in a way the each constructor performs diff task.

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

what are differences btwn constructors and methods

A
c (5)
used to initialize state of objt
must not have return type
invoked implicitly 
provided by compiler
name must be same as class
m
expose behavior of objt
must have return type
invoke explicitly
not provided by compiler
name may or may not be same as class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

= a methodology to design a program using classes and objts.

it simplifies sw dev + maintainance via core concpets of oc pai en

A

oop

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

is a blueprint from which individual objts are created.

A

class

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

any thing that has a state and behavior.

A

objt

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

dev and maint easier. > as complexity increases

hides data whereas procedural allows global.

A

what are advantages of oop over procedural

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

a code block similar to a method.

used to initialized the object.

A

constructor

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

when an object is created. it constructs the value at that time.

A

when a constructor is called

17
Q
3
name = class name
no explicit return type
cant be FASS final, abstract, synchronized, static
A

rules for creating a constructor

18
Q
default = compiler creates w/o parameter
parameterized = has parameter when created
A

what are the types of constructors

19
Q

a technique of having more than 1 constructor w/ diff parameter lists.
arranged in a way the each constructor performs diff task.

A

constructor overloading

20
Q
used to initialize state of objt
must not have return type
invoked implicitly 
provided by compiler
name must be same as class
m
expose behavior of objt
must have return type
invoke explicitly
not provided by compiler
name may or may not be same as class
A

differences btwn constructor and method

21
Q

What are the pillars of oop

A

Polymorphism
Abstraction
Inherientence
encapsulation

22
Q

what are advantages of encapsulation

A

read-only or write only
control over the data
data hiding
easy to test

23
Q

what are access modifiers

A

private
public
protected
default

24
Q

Polymorphism
Abstraction
Inherientence
encapsulation

A

What are the pillars of oop

25
Q

read-only or write only
control over the data
data hiding
easy to test

A

what are advantages of encapsulation

26
Q

private
public
protected
default

A

what are access modifiers

27
Q

What is inheritance

A

is when a child object inherits the attributes and behaviors of a parent class. aka IS-A relationship.

eg: real world

a couple may have a child and the child can inherit similar attributes from the parent’s such as eye color, shape of nose etc. and behaviors such as a way of walking, or talking.

eg: java

2 watches. the parent is dial and the child is digital.

the fx of the parent class watch is displaytime(), display(date) and day.
the fx of the child class will be the same as the parent + displaylight(), setAlarm(), setTimer(). 

Because 3 fxs are repeating we redundancy will be eliminated by the child inheriting fxality from the parent.

if time———————–

4 types of inheritance

  1. single
  2. multiple level
  3. hierarchical
  4. hybrid (combo)-of more than one inheritances.

multi inheritance not supported to reduce complexity.

28
Q

What is abstraction

A

process of allowing the user to focus only on the essential fx of things by abstracting away the details.

eg: real world

let’s say a user wants to sit down. they can sit on a chair, stool, table. each has unique implementation a chair may have a straight back with 4 legs, a stool with a single pillar of support and and table with 4legs no back support. But, the user simply wants a place to sit. Abstraction allows the focus on the main thing “sitting” and not the implementation of it.

eg: Java

2 ways to achieve abstraction:

  1. abstract class
  2. interface.
  3. an abstract class = is a class where objects can’t be created from it.
  4. to declare a class as abstract, you would type the keyword “abstract” before the class name.
    - ————————
  5. interface = similar to a class. a collection of abstract methods.
  6. to declare an interface we would type the keyword “interface” before the NameOfInterface.

eg interface Animal {

  • –eat()
  • -travel()
29
Q

What is Polymorphism

A
Poly = many 
Morph = the ability to change forms. 

eg: real world

could be a man. sometimes he plays the role of a husband, employee, father, owner etc.

or, an actor changing characters depending on the role.

eg: java

2 forms

method overloading
method overriding

method overloading = a class w/ many methods with same name, but different params.

eg - method overloading

2 ways to overload a method

  • change the quanity of params
  • change the quality (data types).

eg quantity x to xy
quality (data type) int > str

method overriding = same method, diff implementations.

eg - method overriding

we can establish a parent class called animal w/ a method called eat() that prints “munch “munch”

we can then establish two child objts called dog and cat.

we know that the children will inherit the attributes and methods from the parent class.

But we can OVERRIDE the parent’s method to print “chump chump” instead of “munch munch” to be more applicable to the dog. We can apply the same process to the cat objt.

Therefore, same method with different implementations.

30
Q

What is encapsulation

A

ability of a class to wrap its data and methods into a single unit.

eg - real world

our home is an encapsulated area where we store things valuable to us.
it has specific areas such as living rm, kitchen, bedroom where we can store a safe.
if we have several people coming to our home such as a cleaning person, cook etc, other family members etc, the main question is who can ACCESS what?

access modifiers helps with this. they are

private
public
default
protected

eg the home can req a security code to enter.

private - only the head of household
default - entire family has code
protected = default + a few relatives.
pubic = put code on social med.

eg - java

a class encapsulates the state(attributes) and methods. 
the data is not accessible to outside sw programs. only the fxs wrapped inside can access it.
the access modifiers can be defined at the class level, var level and method level. 
-------------------
therefore, encapsulation is binding the state and methods into a single unit or class.