Week 8 - OOP - Object Oriented Programming Principles and Intermediate Java Flashcards

1
Q

4 pillars of OOP

A

Abstraction
Inheritence
Polymorphisim
Encapsulation

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

What is inheritance?

A

Inheritance is all about inheriting the common state and behavior of parent class (super class) by its derived class (sub class or child class). A sub class can inherit all non-private members from super class, by default.

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

Inheritance can be one of four types – depending on classes hierarchy. Name them:

A

Single inheritance
Multi-level inheritance
Hierarchical inheritance
Multiple inheritance

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

What is Single inheritance

A

There is one Parent class and one Child class. One child class extends one parent class

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

Multi-level inheritance

A

In multilevel inheritance, there will be inheritance between more than three classes in such a way that a child class will act as parent class for another child class.

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

Hierarchical inheritance

A

In hierarchical inheritance, there is one super class and more than one sub classes extend the super class.

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

Multiple inheritance

A

In multiple inheritance, a class can inherit the behavior from more than one parent classes as well.

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

____ is a type of inheritance where there is one Parent class and one Child class. One child class extends one parent class.

A

Single inheritance

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

____ is a type of inheritance where there is one super class and more than one sub class extend the super class.

A

Hierarcihal inheritance

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

What is an object class?

A

a special class in Java which is the root class from which all other classes inherit, either directly or indirectly.

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

The _____ method returns a copy of this object.

A

clone

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

The _____ method returns a Class object that represents this object’s runtime class

A

getClass

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

The _____ method returns a String representation of this object.

A

toString

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

In java equals() method is used to compare equality of

A

two Objects

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

_____ is the default implementation of the equals() method which only checks if two object references refer to the same object.

A

Shallow comparison

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

_____ is where data members of objects are to be compared with one another.

A

Deep comparison

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

During the execution of the application, if hashCode() is invoked more than once on the same object then it must consistently return the same Integer value. T/F

A

True

18
Q

Different executions of the same application using hashcode() must produce the same integer every time. T/F?

A

False

19
Q

What is polymorphism?

A

“taking on many forms”. In the realm of programming, it describes how objects can behave differently in different contexts. The most common examples of polymorphism are method overloading and overriding.

20
Q

What is method overloading ?

A

is when there exist two or more methods in a class with the same method name, but different method signatures by changing the parameter list.

21
Q

What is method overriding>

A

is when a method in a child class has the same method signature as a method in the parent class, but with a different implementation. Thus, child classes can change the default behavior given by a parent’s method. Overriding methods makes class hierarchies more flexible and dynamic.

22
Q

What does object-oriented programming mean?

A

Programming constructs are objects which model real-world concepts and can be put into hierarchies, and the relationship between objects are managed

23
Q

What is the difference between classes and objects?

A

Classes are the templates from which objects are instantiated

24
Q

What does polymorphism mean?

A

Allowing the implementation of a given behavior to vary, whether between subclasses or within the same class

25
Q

What are generics?

A

constructs introduced in Java 5 which enforce compile time safety by allowing you to use parameterized types.

26
Q

Generics can be declared on a

A

class (generic types), method parameters (generic methods), or return types.

27
Q

With generics, you can restrict a class to only

A

accept objects of a given type and the compiler will prevent you from using any other type.

28
Q

_____ are constructs introduced in Java which enforce compile time safety by allowing you to use parameterized types.

A

Generics

29
Q

To make a class (or interface) generic, use _____ when declaring it

A

angle brackets

30
Q

what is abstraction?

A

It involves identifying common characteristics and generalizing behaviors into conceptual classes. You can think of it as a way to simplify code by focusing on what objects have in common, rather than their individual differences. Abstraction helps to make code more modular, reusable, and easier to maintain. So, instead of dealing with individual objects, we create abstract classes that define the common features of related objects. This way, we can write more generic code that can handle a variety of objects, rather than having to write specific code for each one.

31
Q

Through abstraction, we hide

A

underlying complexity through a simplified interface

32
Q

What is encapsulation?

A

involves bundling related data and behavior into a single unit called a class, and hiding it from other parts of the program. You can think of it like a box that contains everything related to an object and controls access to it. This helps to prevent external interference that could potentially cause the object to become invalid or inconsistent. Encapsulation allows for better organization, modularity, and security of code. It also makes it easier to change the implementation details of a class without affecting the rest of the program. So, to sum up, encapsulation is about bundling data and behavior together, and hiding it from the rest of the program to ensure data integrity and security.

33
Q

What does encapsulation mean?

A

Restricting access to data members by using access modifiers and getter/setter methods

34
Q

Encapsulation means that data should only be accessed through setter and getter methods T/F

A

True

35
Q

An interface is similar to an abstract class, but one of many differences is that

A

a class can only inherit one other class, but a class can implement as many interfaces as it needs.

36
Q

Interfaces have these advantages over class

A

Implementation details do not need to be provided in the interface.

A class can only extend one other class, but it can implement as many interfaces as needed.

37
Q

Interfaces have implicit modifiers on methods and variables:

A

Methods are ‘public’ and ‘abstract’
Variables are ‘public’, ‘static’, and ‘final’

38
Q

Which is NOT a true statement about the Java programming language?
A class can inherit from multiple classes
A class can only inherit from one class
Interfaces are created using the implements keyword
A class can implement any interfaces as needed.

A

A class can inherit from multiple classes

39
Q

To inherit interfaces, a class must implement them and they are REQUIRED to implement all methods, unless the class is ___?

A

abstract

40
Q

Interfaces have implicit modifiers on methods and variables. Which of these are NOT one of those implicit modifiers?
virtual
public
static
final

A

virtual

41
Q

Comparable is an interface which defines

A

the natural ordering for a class. A class must implement Comparable if it is to be sorted by the compareTo() method.