Introduction Oops Java Interview Questions And Answers
Oops, popularly known as Object-Oriented Programming techniques is the programming paradigm that revolves around the concept of objects. In an OOP language such as Java, everything is an object which contains data, fields, attributes and we code them in the form of procedures, also known as methods. It also comprises of class-based parameters which provide meaning to instances, determinant on their type. Oops, revolve around the basic concepts of Abstraction, Polymorphism, Inheritance, Encapsulation, Objects, classes, and interfaces. Here in this post, we have compiled a list of most commonly asked and important Oops Java interview questions and answers.
Now, if you are looking for a job that is related to Oops Java then you need to prepare for the 2020 Oops Java Interview Questions. It is true that every interview is different as per the different job profiles but still to clear the interview you need to have a good and clear knowledge of Oops Java. Here, we have prepared the important Oops Java Interview Questions and Answers which will help you get success in your interview.
Below are the 8 important 2020 Oops Java interview questions and answers that are frequently asked in an interview. these questions are divided into parts are as follows:
Part 1 – Oops Java Interview Questions (Basic)
This first part covers basic Interview Questions and Answers
1. What are the different OOPs concepts?
Different OOPs concepts are as follows:
2. What is polymorphism? Can we override a static method and a private method in java?
This is the most common Oops Java Interview Question which is asked in an interview. The ability of the identification of a function during its runtime phase is called Polymorphism. In most object-oriented programming languages such as C++ and Java, there are two types of polymorphisms, compile-time polymorphism (overloading) and runtime polymorphism (overriding).
Method overloading: The ability of a method to have the same method names but different parameter numbers or types is called method overloading.
Method overriding: It occurs when the class method of a child class consists of the same name and the method signature as that of the parent class. When you override methods, the proper method is identified by the JVM to call at its program’s run time and not at the compile time.
No, it is impossible to override a static method in Java as it is not bounded by the object. Static methods, on the other hand, are class-dependent and are resolved at the compile time using reference variable type. Declaring the same method inside a subclass will result in method hiding.
No, it is impossible to override a private method in java. As the private method is accessible and visible inside the class in which they are declared, they cannot be overridden inside the subclass. Though, they can be overridden inside the inner class as they can be accessed here.
Let us move to the next Oops Java Interview Questions.
3. What are some of the important Java 8 features?
Some of the important features introduced in Java 8 are:
- forEach() method in iterable interface
- Lambda expressions and functional interfaces
- Static and default methods in interfaces
- Java time API
- Stream API for bulk data operations on collections
- Concurrency API improvements
- Collection API improvements
- Java IO improvements
- Core API improvements
4. What is the difference between State and Strategy Patterns? What problem is solved by the Strategy pattern?
State pattern and the strategy pattern share the same structure or class diagram, however, their intent is completely different. State patterns work on specific tasks depending on the states while the strategy works on switching the algorithm without changing the code. For example, a method, collections.sort() sorts the object list. Since all the objects use a different comparison strategy, comparison among various objects can be done without any need of changing the sort method.
Part 2 – Oops Java Interview Questions (Advanced)
Let us now have a look at the advanced Interview Questions.
5. What are the 5 design principles for an object-oriented approach from SOLID?
The Book, Clean Code, written by Uncle Bob, each character in SOLID stands for one design principle:
S- Single Responsibility Principle
O- Open closed design principle
L- Liskov substitution principle
I – Interface segregation principle
D- Dependency inversion principle
Let us move to the next Oops Java Interview Questions.
6. Upon which OOP concept the Decorator design pattern is based?
The decorator pattern takes advantage of the OOP feature of Composition to provide new features without the need for modifying the original class. The component is associated with the Decorator.
7. What is the difference between Association, Dependency, Composition, and Aggregation in OOP?
In case of an association, one class has a member variable or an attribute of the other class type but in case of dependency, a method is involved in an argument of the class type or in the local variable of other class types.
There are two forms of associations, aggregation, and composition. Aggregation is the loose form of association where the related object survives individually whereas, in case of composition, the object cannot survive individually.
8. What is ThreadLocal? Do we prefer the synchronized block or synchronized method?
All the threads of an object share the variables, so the variable is not threaded safe.
This has been a guide to List Of Oops Java Interview Questions and Answers so that the candidate can crackdown these Interview Questions easily. Here in this post, we have studied about top oops java Interview Questions which are often asked in interviews. You may also look at the following articles to learn more