OOP Flashcards

1
Q

class

A

template of blueprint from which objects are created and receive their states(properties/fields) and behaviour(methods)

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

static

A

class method
belongs to class
don’t need an instance to use it
underline

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

non static

A

instance method
belongs to object
need that instance to call it

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

void

A

method doesn’t return anything

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

object

A

an instance of a class
there can be multiple instances of a class in a program.
contains both the data and the function, which operates on the data.
has its own unique properties(data) and each method can be called on each object.

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

abstraction

A

displaying only essential information and hiding the details.

creating new data types suited for a specific application (that the programming language does not know about.)

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

encapsulation

A

hiding the code and data into a single unit/method/class (protect inner workings of an object)

makes use of information hiding (make properties private - use methods to access them.)

functionality + data of object organised into a single structure by concealing the implementation of the object. done by declaringdata types as private

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

information hiding

A

inner workings of a class being hidden from the class user

use access modifier private (in order to have encapsulation)

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

difference between abstraction and encapsulation

A

Abstraction hides details at the design level (complexity) , while Encapsulation hides details at the implementation level (inner workings).

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

public

A

Accessible everywhere
can be accessed by the class.it is declared in and by by any other class
+

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

private

A

-
Accessible only in its own class

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

protected

A


Accessible by class and any subclass (in any package) and by any other class in the same package

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

inheritance

A

one object acquires the properties and behaviours of the parent object (along w having their own unique attributes)

key word- extends use clear arrow

parent- child relationship between superclass + subclass

suitable when 2 classes have many fields + methods in common

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

default constructor

A

constructor w/ no parameters
sets attributes of the object to default values

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

polymorphism

A

ability of a variable/object or method to take on multiple forms based on its current situation
overriding + overloading

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

variables

A

Fields/Attributes/Characteristics/Properties

describe the objects properties
store data for processing.

given a name (identifier), are of a specific type and have a value assigned to it.

all take up a different amount of size + has a unique address

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

local variables

A

declared inside methods
do not exist when method is finished, cannot be used outside of method
used instead of global- space in RAM not wasted
Different methods can have local variables with the same names because the methods cannot see
each other’s local variables.

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

global variables

A

declared in class above all methods
scope is inside the entire program
can be used by all methods

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

access modifiers

A

used to tell which code has access to certain fields and methods

20
Q

types of variables

A

primitive- cant invoke methods
reference/class type.-has methods

21
Q

types of variables

A

primitive- cant invoke methods
reference/class type.-has methods

22
Q

constructor

A

special method in class called when an object is instantiated
purpose- initialise class fields

23
Q

accessor method

A

get method
have a specific data type/ return type
returns a field value
allows for visibility of data - other classes will have access tonthd values
no parameters

24
Q

mutator method

A

set method
modify field values
void
other classes can edit data of object
has parameters

25
Q

typed methods

A

return a value

26
Q

void methods

A

don’t return a value

27
Q

helper methods

A

declared as private
solve some problem in the class
called by public methods in the class

28
Q

instantiation

A

act of creating an object from the class

29
Q

scope of variable

A

defines where variable can be used in a programme and its lifetime
depends on where it is declared in the program
local or global

30
Q

method overloading

A

creation of multiple methods in a single class with the same name but with different method signature (parameters/data types )
—method signature changes
-done innone class
can overload static,final or private method
-bonded by static binding at compile time

31
Q

method overriding

A

child class uses method created in parent class (same name)

@override

-method signature remains the same
-only done in subclass
-cannot override static,final + private method
-subject to dynamic binding at run time (check which method to use )

32
Q

method resolution

A

When you have methods that have been overloaded, Java needs to figure out which method to call based on the parameters given when the method is called.

33
Q

constants

A

cannot be assigned another value later in the programme
public static final NAME

34
Q

formal vs actual parameters

A

actual- when you call a method and pass real values in it
formal-when you create a method and pass values as parameters

35
Q

method signature

A

first line that describes whether or not the method is typed or void, what its name is, what parameters it contains,

modifier,return type,name,parameters

36
Q

reasons protected access does not offer secure protection

A
  1. Anyone can create a subclass from an
    existing class and could therefore access and change values in fields which could have dire consequences on applications using those classes.
  2. In Java, all classes in the same package have access to protected fields, whether or not they are subclasses.
37
Q

default access

A

nothing specified

Accessible by any class or subclass in the same package. This is sometimes called package accessibility

38
Q

array

A

data structure
collection of variables of same type
elements ordered + each has a specific + constant position (index)

39
Q

method

A

collection of statements that are grouped together to perform an operation
defines behaviour

40
Q

toString method

A

create String representation of an object.
every class has default toString method

41
Q

for loops

A

allows you to efficiently write a loop that needs to execute the same code a specific number of times.
for (initialisation,condition,change) { action}

42
Q

while loops

A

repeatedly executes a target statement as long as a given condition is true.
initialisation
while (condition is true) { action
change}

43
Q

advantages of inheritance

A

Reusability of code: we can use our existing code in our subclass from the super class
• Subclasses can take on existing functionality while creating their unique methods for their access only
• information hiding

44
Q

advantages of encapsulation

A

guarantees integrity of an object’s data as it is securely hidden
restricted data access from outside sources

45
Q

call method from parent class (override)

A

super.methodName()

for constructor - super(field,field)

46
Q

composition

A

The has-a relationship between two Java objects. One object is a field of another object.