Option D Flashcards

1
Q

Outline the general nature of an object.

A

In general an object can be defined as a location in memory having a value. This could be a variable or data structure. Usually when talking about objects it refers to instances of a class.

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

What are the three rows of a UML diagram?

A
  1. Class name
  2. Variables
  3. Methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the structure of a variable in a UML diagram?

A

varName : type ( = value)

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

What are the three types of relationships between objects?

A

The three types of relationships that should be known are dependency (“uses”), aggregation (“has a”) and inheritance (“is a”).

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

Explain aggregation.

A

Aggregation is a type of relationship between objects. It means that one type of object contains another or is composed of another. Some examples are: a car has-an engine, a bicycle has-a wheel, and a coffee cup has coffee.

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

Explain inheritance.

A

Inheritance is a type of relationship between objects. It means that one type of object is a more specific version of a general type. Some examples are: a car is-a vehicle, a bicycle is-a vehicle, and a coffee cup is-a cup.

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

Explain dependency.

A

Dependency is a type of relationship between objects. It means that during some activity, one type of object uses another type of object. Some examples are: a car uses-a squeegee (during a window-washing activity), a bicycle uses-a pump (during a tire-pumping activity), and a coffee cup uses-a stirrer (during a stirring activity).

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

How are dependency and aggregation represented in a UML diagram with multiple classes?

A
In UML:
A dependency (when one dies, the other dies) is represented by a shaded diamond

An aggregation is represented by a hollow diamond

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

What are the two parts of an object?

A
  1. Attributes (variable names)

2. Behaviour (Methods)

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

What are the four fundamental OOP concepts?

A
  1. Encapsulation
  2. Abstraction
  3. Inheritance
  4. Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Encapsulation and abstraction are _____ concepts.

A

Complementary

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

What’s the major difference between abstraction and encapsulation?

A

Just like abstraction, encapsulation hides data, but at a deeper level.

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

What is encapsulation?

A

Encapsulation is the process of combining data and methods into a single unit (class). In Encapsulation, the data is not accessed directly; it is accessed through the methods present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible.

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

What is inheritance?

A

Inheritance enables programmers to define an “is-a” relationship between a class and a more specialized version of that class. For example, if a Student class extends a Person class, then it should be the case that Studentis-aPerson. The subclass Student builds on the functionality of the superclass Person.

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

If a parent class is shapes, list some child classes it can have?

A

triangle, rectangle etc.

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

What is polymorphism? What are the two types?

A

Polymorphismrefers to a programming language’s ability to process objects differently depending on their data type or class. The two types are method overloading and method overriding.

17
Q

Describe method overriding.

A

Method overriding is a type of polymorphism that allows a subclass or child class to provide a specific implementation of amethodthat is already provided by one of its superclasses or parent classes. Method overriding allows a sub class to use all the general definitions that a super class provides and add specialised definitions through overridden methods.

18
Q

Describe method overloading.

A

Method overloadingis a type of polymorphism that allows a class to have two or moremethodshaving same name, if their argument lists are different. Method overloading allows methods that perform similar or closely related functions to be accessed through a common name.

19
Q

What is the main advantage of encapsulation?

A

The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature, encapsulation gives maintainability, flexibility and extensibility to our code.

20
Q

List 3 advantages of inheritance.

A
  1. Reusability - ability to use public methods of base class without rewriting the same
  2. Extensibility - extending the base class logic as per business logic of the derived class
  3. Data hiding - base class can decide to keep some data private so that it cannot be altered by the derived class
  4. Space saving
21
Q

List 2 advantages of polymorphism

A
  1. Method overloading can be used so that we do not have to find alternative and meaningful names for two methods that perform the same things with slight differences (e.g. different data types)
  2. Method overriding works together with inheritance to enable code reuse of existing classes without the need for re-compilation.
22
Q

What are libraries?

A

Pre-defined sets of codes that could be used.

23
Q

Why are libraries useful?

A

The main advantage of using libraries of objects is so that sorts and other complex algorithms and processes do not have to be “re-invented”, thus saving time.

24
Q

List 3 disadvantages of OOP.

A
  1. May not be useful for very simple procedures
  2. Larger file size
  3. Slower
  4. Steep learning curve
25
Q

List 6 advantages of modularity

A
  • If a single procedure is developed it can be reused multiple times without having to retype the code (reusability)
  • Programs can be designed more easily and more effectively due to the divisions of the entire code into sectors because a small team deals with only a small part of the entire code (focus)
  • Modular programming allows many programmers to collaborate on the same application (team management)
  • Code is short, simple and easier to understand (readability)
  • Scoping of variables can be easily controlled (code management)
  • When errors are localized to a subroutine or function, they can be easily identified (debugging)
26
Q

What is a class?

A

a blueprint or template for objects

27
Q

What is an identifier?

A

namesof variables, methods, classes, packages and interfaces etc.

28
Q

What are primitive data types?

A

Types of data that are predefinedin the programming language

29
Q

What is an instance variable?

A

avariabledefined in a class (i.e. a membervariable), for which each instantiated object of the class has a separate copy, orinstance

30
Q

What is a local variable?

A

variables declared in methods or blocks and is destroyed when the program exits the block

31
Q

What is a method?

A

a sub-procedure/sub-program in java that forms part of a class/object

32
Q

What is an accessor?

A

a method used to get/return some properties of an object (used in encapsulation to get value of private variable)

33
Q

What is a mutator?

A

a method used to change properties of an object (used in encapsulation)

34
Q

What is a signature?

A

the method signature contains the parameters and names of a method, used to distinguish between two methods with the same name in polymorphism

35
Q

What does the “private” keyword do?

A

signals that only visible in the class it’s in

36
Q

What does the “public” keyword do?

A

signals that visible in all classes

37
Q

What does the “protected” keyword do?

A

signals that only visible in the class it’s in and any subclasses

38
Q

What does the “extends” keyword do?

A

signals the creation of subclass

39
Q

What does the “static” keyword do?

A

signals that the variable or function is shared between all instances of that class not to the object itself