OOP Flashcards

1
Q

What are the 4 pillars of OOP?

A

Abstraction, Polymorphism, Inheritance, Encapsulation

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

Abstraction

A

The process of hiding complex processes behind a simple user interface. This can be seen with the usage of the Abstract keyword, which is a non-access modifer, used for classes and methods. Abstract classes are restricted classes that cannot be used to instantiate objects. Abstract methods do not have a body and can only be used in abstract classes.

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

Polymorphism

A

Means many forms and extends from inheritance. Refers to the ability for for parts of code to be reused and modified based on the context of its usage. Examples are Method overloading and method overriding.

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

Inheritance

A

Refers to the adaptation of variables and methods from the parent class to the child classes. The child classes can then change the values of the variables and methods for its own specific usage. Multiple inheritance is not supported in Java.

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

Encapsulation

A

The wrapping of blocks of code into a single unit and then selectively giving or restricting access to that code through the use of access modifiers. Is also seen with the usage of getter and setter methods which further protects your code from being altered.

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

What is the difference between an abstract class and an interface?

A
You cannot instantiate an abstract class, and forces programmers to instantiate its child classes.
	While an interface is more like a contract and declares behaviors that other classes must implement, or that class itself must be abstract. In an interface methods are implicitly abstract.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can abstract classes have concrete methods? Can concrete (non-abstract) classes have abstract methods?

A

An abstract class can only have abstract methods. A concrete class can have abstract methods.

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

Can static methods access instance variables? Can non-static methods access static variables?

A
No a static method cannot access an instance variable. Yes non-static methods can access static variables. 
       Static methods are methods that belong to a class rather than an instance of a class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the implicit modifiers for interface variables? Methods?

A

Interface methods are implicitly abstract and public. All instance variables are implicitly constant, static and final.

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

What is the difference between method overloading and overriding? What are the rules for changing the method signature of overloaded methods?

A

Method overloading is when methods have the same name but different types and/or number of parameters. Method overriding has the same name and same parameters but occurs when a child class inherits a method from a public class and then changes the implementation of that method for its own use.

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

What are covariant return types? What rules apply to return types for overridden methods?

A

Covariant return types are the return types of overriden methods. It allows the program to narrow down the return type of an overridden method without any need to cast the type or check the return type.

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

When do you see extends or implements keywords?

A

Extends is used for classes. Implements is used for interfaces.

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