Abstraction Flashcards
What is abstraction in OOP?
It is the process of hiding certain implementation details and showing only essential features to the outside world.
How is abstraction different from encapsulation?
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.
What is an abstract class?
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.
Can you have an abstract method in a normal class?
No, as per the spec, if a class contains at least one abstract method, it must be declared abstract.
What is an interface in Java?
An abstract type blueprint of a class. It contains the methods that a class must implement.
Why an interface cannot be marked as final?
A final method cannot be overridden, but an interface method has to be implemented by another class, so it cannot be marked as final.
Can we use private or protected modifiers for variables in interfaces?
No. All variables in an interface are implicitly public.