OOP Flashcards

1
Q

What Is OOP

A

a type of computer programming (software design) in which programmers define not only the data type of a data structure, but also the types
of operations (functions) that can be applied to the data structure.
In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example,
objects can inherit characteristics from other objects.

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

What are the advantages of OOP

A

-Code Reuse
-Encapsulation
-Design benefits as easier to program due to extensive planning phase at beginning
-Software maintenance is easy

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

What is encapsulation

A

a programming language construct that facilitates the bundling of data with the
methods (or other functions) operating on that data.
Encapsulation is an OOP concept where object state(class fields) and it’s behavior(methods) is
wrapped together. Java provides encapsulation using class.

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

What are the benefits of encapsulation

A

-you can use a method without knowing how it works. Once an
Object is created
-hide certain parts of themselves from
programmers. This prevents progrmers from tampering with values they
shouldn’t.
-object controls how one interacts with it, preventing
other kinds of errors.

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

What is a class

A

a construct that is used to define a distinct new type and is made up of
properties (attributes) that are grouped together to describe the object and
functions and procedures (methods/behaviour) that describes what the object can do.

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

What other words can be used to describe a class

A

-a building plan for a house
-a template
-a blueprint

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

What does the first part of a UML diagram show

A

properties/ fields of class with their data types – describe what object “looks
like”

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

What does the second part of a UML diagram show

A

methods

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

What does the + access modifier mean

A

accessible from outside class in any other class

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

What does the - access modifier mean

A

NOT accessible from outside class

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

What does the access modifier protected mean

A

only accesible in child class that inherits from parent class.

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

What is an object

A

a dynamic instance of a class.

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

How is an object instantiated

A

Using the constructor

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

What is a constructor

A

code in a special method that
will create the object in memory while the program is running.

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

What a the relationship between objects and classes

A

Many objects can be created
from the same class. Just like you can declare many variables of the same type, you can have
many instances of your class as objects in one application Each object can have its own values

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

What is information hiding

A

a programming language mechanism for restricting access to some of the
object’s components. When fields and methods are declared under private in the class, it is only
visible in the object itself. These private variables and methods are protected against
unintentional modification.

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

How can you access private variables

A

by using typed methods to
get the values and make it available to the unit where the object is used.(getters)

18
Q

How do you change private variables

A

by using void methods to
set values.(setters)

19
Q

What are the constructor, accessor and mutator methods set as

A

The Constructor, Accessor methods and Mutator methods must be declared as public so
that other units can use them.

20
Q

How do you determine the name of a constructor

A

The name of a constructor must be the same name as the class

21
Q

Is it possible to have more than one constructor

A

Yes !
Like a no argument constructor which is the default constructor etc

22
Q

What is an argument list

A

The parameters of the constructor (The variables in the brackets next to the constructor )

23
Q

What are the two types of constructors

A

Parameterised constructor and default constructor

24
Q

What is a parameterised constructor

A

You can provide your constructor with parameters to
initialise fields to values of your choice each time the constructor is called

25
Q

What is a default constructor

A

The default constructor uses the inherited create constructor to set
the strings to empty fields and numeric values to 0 if it is not defined, but you can code
the default constructor to set initial values

26
Q

What is overloading

A

When a class have two methods with the same name, with different parameters
(Ie define two constructors using the same name, with different parameters)

27
Q

What are the characteristics of accessor methods (getters)

A

always typed method
always brackets
always returns a value

28
Q

What is an accessor method

A

a typed method in the class that makes private variables in the class
available to the driver class or any other unit.

29
Q

What is a driver program

A

A class with a form

30
Q

How would you call an accessor method in the driver class

A

object.methodname()

31
Q

What are the characteristics of mutator methods (setters)

A

always void method
Sometimes a parameter in brackets with new value
no return statement

32
Q

What is a mutator method

A

a procedure to change or set the private variables in the object after the
object was instantiated. You make use of mutators to transfer the new values to the private
variables.

33
Q

How would you call a mutator method in the driver class

A

object.methodname(changed value)

34
Q

What is an auxiliary method

A

any other methods in the class that can assist with calculation or
formatting.

35
Q

What is inheritance

A

mechanism of creating new classes build upon existing ones in which one object takes on all fields and methods of the
parent object.

36
Q

What does the object class do

A

The Object class, defined in the java.lang package, defines and implements behavior common to
all classes—including the ones that you write.

37
Q

What is the keyword in inheritance

A

Super

38
Q

How to check it an object is an instance of a particular class

A

Use instanceof

39
Q

What type of members can a subclass inherit from its parent class

A

A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected (other classes cannot use these variables but child classes can) methods for accessing its private fields, these can also be used by the
subclass.

40
Q

How to override the superclass

A

You can write a new instance method in the subclass that has the same signature as the
one in the superclass, thus overriding it

41
Q

How to hide the super class

A

You can write a new static method in the subclass that has the same signature as the one
in the superclass, thus hiding it.

42
Q

What is overriding

A

when the child class has a method of the same name and parameters as the parents
thus hiding the parent’s method