Interview questions 3 Flashcards

1
Q

public access modifier meaning in Java

A

Can be accessed by other classes

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

private access modifier meaning in Java

A

Cannot be accessed by other classes

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

protected access modifier meaning in Java

A

Declarations are visible within the package or all subclasses

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

Default access modifier in Java

A

Declarations are visible only within the package (package private)

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

Reason for not using public access mods

A

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.

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

Reason to use private access mods

A

There is a lot less code you have to pay attention to when you make changes.

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

What is a wrapper class?

A

Wrapper classes provide a way to use primitive data types (int, char, short, byte, etc) as objects.

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

Purpose of a wrapper class.

A

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).

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

What does a helper class do?

A

Provides common methods which are required by multiple classes in the project.

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

How many classes (superclass) can a class extend?

A

Only one.

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

Difference between hashset & list.

A

In hashset, no duplicates are allowed, and it is unordered.

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

What is decoupling & benefits?

A

Making components as independent as possible from one another. Makes code easier to understand.

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

Why is polymorphism desirable & what are some drawbacks?

A

Helps with reusability of code and makes it easier to read.

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

4 pillars of oop.

A
  • abstraction
  • encapsulation
  • inheritance
  • polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

stack vs heap.

A

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.

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

What is abstraction?

A

Hide the implementation details of something so that when you call a function you only have to know what it does, not how it does it.

17
Q

what is encapsulation?

A

In encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of its own class in which it is declared. Another way to think about encapsulation is, that it is a protective shield that prevents the data from being accessed by the code outside this shield. Use private vars in class or make var only accessible through getters & setters.