OOP Flashcards

1
Q

what are the components of an object

A
  1. states: can be variables or data structures
  2. behaviors: can be functions, procedures or methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the components of an object?

A
  1. states(data): can be variables or data structures
  2. behaviors(actions): can be functions, procedures or methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is an object?

A

particular instance of a class, where the object can be a combination of variables or data structures (called states) and functions, procedures and methods (called variables)

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

UML diagram components

A
  1. ClassName
  2. State (variables) e.g.:
    - name: String
    - age: int
  3. behaviors (state) e.g.:
    + getAge() : String
    - setName( name: String ) : void
  • private
    + public
    # protected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

dependency

A

it increases maintenance overheads, meaning that changes that need to be made to the entire system if you make a change to a component

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

encapsulation

A

technique of making the states in a class private and providing access to those states via public behaviors (methods). data and actions are limited to the object in which they are created.
if a state is declared private, it cannot be accessed by any method outside the class. encapsulation is also referred as data hiding.

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

Advantages of encapsulation

A
  1. Data hiding
    the user will have no idea about the inner implementation of the class - implies security.
    it will not be visible to the user that how the class is storing values in the variables.
    He/she only knows that we are passing the values to a setter method and variables are getting initialized with that value
  2. Increased Flexibility
    we can make the variables of the class as read-only or write-only depending on our requirement
    if we wish to make the variables as read-only then we can omit the setter methods
    or if we wish to make the variables as write-only then we have to omit the get methods
  3. Reusability
    Encapsulation also improves the reusability of code
    methods can be copied to different/new classes and help meet new requirements
  4. Testing code is easy
    encapsulated code is easy to test with unit testing
    it’s easier to fix larger programs if you know which method is returning the wrong example
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Inheritance

A

process whereby one object inherits the properties (states and behaviors) of another object (pairs called super/sub or parent/child classes)
Java keyword inherits means extends

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

advantages of Inheritance

A
  1. Minimize the amount of duplicate code in an application
  2. better organization of code
  3. code more flexible change
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Polymorphism

A

it means many forms; two methods can have the same name but different contents/functions
methods have the same name but different parameter lists and processes.

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

Polymorphism: overloading

A

allows different methods to have the same name, but different signatures where signature can differ by number of input parameters or type of input parameters or both.
we don’t have to create and remember different names for functions doing the same thing. e.g. if overloading was not supported by Java, we would have to create method names like sum1, sum2… or sum2int, sum3int…

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

Polymorphism: overriding

A

allows a sub class to provide a specific implementation of a method that is already provided by one of its super classes
when a method in a subclass has the same name, same parameters or signature and same return type as a method in its super-class, then the method in the subclass is said to override the method in the super-class.
“one interface, multiple methods”.
it allows us to call methods of any of the derived classes without even knowing the type of a class.

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

why is polymorphism essential to OOP?

A

it allows general class to specify methods that will be common to all of its derivatives, while allowing sub classes to define specific implementation of some or all of those methods

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

disadvantages of OOP

A
  1. increased complexity for small problems:
    Involves more lines of code than procedural programs.
    It’s slower than other procedural programs as it requires more instructions to be executed.
  2. unsuited to particular classes of problems:
    there are problems that lend themselves well to functional programming style, logic-programming style or procedure based programming style and applying OOP in those situations will not result efficient programs.
    e.g. why make an object when using a string will do?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is modularity?

A

Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules. Modularity is supported by using different code files and classes. Codes are more efficient because of features of OOP.

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

advantages of modularity

A
  1. easier debugging and testing (as it has smaller modules)
  2. speedier completion: by breaking the projects into smaller modules, you can save time of looking for the specific modules
  3. reusable code blocks:
    some problems/functions are very common and possibly occur in multiple different programs, so development time is slashed and it’s done sooner
17
Q

class

A

program-code-template for creating objects, providing initial values for states and implementations of behaviors

18
Q

identifier

A

named pointer that explicitly identifies an object, class, method or variable.
it allows a programmer to refer to the item from other places in the program
to make the most out of identifiers you choose make them meaningful and follow the standard java naming conventions.

19
Q

primitive

A

most basic data types available within the Java language. we have 8: boolean, byte, char, short, int, long, float and double.
these types serve as the building blocks of data manipulation in Java.
such types serve only one purpose: to contain pure, simple value of a particular kind

20
Q

variable

A

provides us with named storage location for a value that a program can manipulate.
they must be declared before they can be used and can only contain data of a particular type.

21
Q

instance variable

A

they are non-static variables and are declared in a class outside any method, constructor or block.
they are declared in a class, these variables are created when an object of the class is created and destroyed when object is destroyed.
unlike local variables, we may use access modifiers (public, private, protected) for instance variables

22
Q

parameter variable

A

parameters allow us to pass information or instructions into functions/procedures. parameters are the names of the information that we want to use in a function or procedure.
values passed in are called arguments.

23
Q

local variable

A

a variable defined within a block or method or constructor is called local variable.
these variable are created when the block is entered or the function is called and destroyed after exiting from the block or when the call returns from the function.
the scope of these variables exists only within the block in which the variable is declared. we can access these variables only within that block.

24
Q

method

A

it’s a set of code which is referred to by name and can be called at the point in a program simply by utilizing the method’s name. a method can be described as a subprogram that acts on data and often returns a value. each method has its own name (identifier)

25
Q

accessor

A

type of method used in Java OOP which returns the value of a private instance (class) variable. it’s also called getter method

26
Q

mutator

A

method used to control changes to a encapsulated instance (class) variable/state. they’re also known as setter methods

27
Q

constructor

A

instance method (defined inside a class) that is invoked when an object of that class is created (by using the new keyword)
object creation rule: when an object is created, one of the constructor method in the class must be invoked (to initialize the instance variables in the object)

28
Q

signature

A

a method signature is part of the method declaration. it is the combination of the method name and the parameter list.

29
Q

procedures vs functions

A

procedures don’t return any value while functions return a value.
no method can return more than one value at a time in Java.

30
Q

public

A

a class, method, field or constructor that is declared public can be accessed from any other class

31
Q

private

A

methods, variables and constructors that are declared private can only be accessed within the declared class itself.
classes cannot be private, but methods and variables can.

32
Q

protected

A

variables, methods, and constructors, which are declared protected in a superclass can be accessed only by the subclasses in any class with the package of the protected members’ class.

33
Q

keyword used in a sub class to inherit the properties of a super class

A

extends extends