Abstraction Flashcards

1
Q

What is abstraction in OOP?

A

It is the process of hiding certain implementation details and showing only essential features to the outside world.

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

How is abstraction different from encapsulation?

A

Abstraction happens at class level design. It results in hiding the implementation details. Encapsulation is also known as Information Hiding. An example of encapsulation is marking the member variables private only providing getters and setters for these variables.

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

What is an abstract class?

A

A class with one or more abstract methods. An abstract method is just declared in the class, but not implemented. This class has to be extended and have their abstract methods implemented. Abstract classes cannot be instantiated.

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

Can you have an abstract method in a normal class?

A

No, as per the spec, if a class contains at least one abstract method, it must be declared abstract.

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

What is an interface in Java?

A

An abstract type blueprint of a class. It contains the methods that a class must implement.

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

Why an interface cannot be marked as final?

A

A final method cannot be overridden, but an interface method has to be implemented by another class, so it cannot be marked as final.

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

Can we use private or protected modifiers for variables in interfaces?

A

No. All variables in an interface are implicitly public.

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