Java Concepts Flashcards

To be strong on concepts and Basics

1
Q

Inheritance vs Composition

A
  1. Composition provides code resusability without extending class, but inheritance code reusability is achieved only through extending classes
  2. Composition you can reuse code for even final class which is not extensible but Inheritance cannot reuse code in such cases
  3. Static vs Dynamic - With inheritance you have to decide in code itself which class to extend but with composition you just need to define the type and at runtime any implementation can be used
  4. Limited code reuse with Inheritance - Inheritance we can extend only one class, but you can have HAS-A relationship with many classes
  5. Unit Testing - U can mock if you use composition, but when it comes to Inheritance, you need to ahve parent class
  6. Final Classes - No inheritance only composition
  7. Encapsulation - Proper coding is required in child class otherwise any changes in the super class will break child calss
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List to Array - Array to List conversion

A

List to Array -> list_reference.toArray(array_reference)
Array to List -> Arrays.asList();

for List to Array, list_reference.toArray() will result in object array to be created

The array and list object becomes joined at the heap, so update in one object updates another. So we cannot add any new element (as array is fixed size), but we can set the values

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

SOLID

A
S -> Single Responsibility Principle
O -> Open/Close Principle
L -> Liskov Substitution Principle
I -> Interface Seggregation
D -> Dependency Inversion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly