Java and OOP

OOP Concepts

Abstraction

Classes, abstract classes, inheritance all abstract the complete details of the members of it.

Encapsulation

Wrapping up of data under a single unit. For example, we declare all instance variables as private and access a few of the, using setters and getters.

Inheritance

Classes are made reusable and they can have parent child relationships.

Polymorphism

One item taking multiple forms is called polymorphism. For example method overloading and overriding.

Reflection

  • Accessing classes, objects and their methods which is generally not possible using regular ways. This is used for writing libraries and other complicated. For example, you can create an instance of an object using just the class name. You can find if a Java item is tagged with a particular annonation and do some additional processing.

Java memory management

Java Interview Questions

Multithreading

Can you access private members (methods and fields) of an object from outside the class?

Yes, we can access them using Java reflection API. Check this GeeksforGeeks article to understand how to do it.

Does HashMap allow null key?

Yes, one null key.

What are differences between abstract class and interface?

  • Multiple interfaces can be implemented by a single class. It is not possible extend multiple abstract classes.
  • Abstract class should be used when there is a parent-child relationship. Interface is used when you want to define only a partial behaviour.