Interview questions 3 Flashcards
public access modifier meaning in Java
Can be accessed by other classes
private access modifier meaning in Java
Cannot be accessed by other classes
protected access modifier meaning in Java
Declarations are visible within the package or all subclasses
Default access modifier in Java
Declarations are visible only within the package (package private)
Reason for not using public access mods
You would have to be careful when you make changes to it, because you never know which parts of the codebase rely on its exact behavior.
Reason to use private access mods
There is a lot less code you have to pay attention to when you make changes.
What is a wrapper class?
Wrapper classes provide a way to use primitive data types (int, char, short, byte, etc) as objects.
Purpose of a wrapper class.
Wrapper Class will convert primitive data types into objects. The objects are necessary if we wish to modify the arguments passed into the method (because primitive types are passed by value).
What does a helper class do?
Provides common methods which are required by multiple classes in the project.
How many classes (superclass) can a class extend?
Only one.
Difference between hashset & list.
In hashset, no duplicates are allowed, and it is unordered.
What is decoupling & benefits?
Making components as independent as possible from one another. Makes code easier to understand.
Why is polymorphism desirable & what are some drawbacks?
Helps with reusability of code and makes it easier to read.
4 pillars of oop.
- abstraction
- encapsulation
- inheritance
- polymorphism
stack vs heap.
stack = linear, heap = hierarchical. Stack = rigid, heap = flexible/ Stack is safer because the data stored can only be access by owner thread, not by all threads like heap memory.