Core Java OOPs Concepts Interview Question .
1) What is the difference between static binding and dynamic binding?
|No.||Static Binding||Dynamic Binding|
|1)||It depends on compile time||It depends on run time.|
|2)||It is also called early binding .||It is also called late binding.|
|3)||Method overloading is the best example of static binding.||Method overriding is the best example of dynamic binding.|
|5)||static, final, and private methods show static binding. Because, they cannot be overridden.||Other than static,final and private, methods show dynamic binding. Because, they can be overridden.|
2) What is the difference between abstraction and encapsulation?
|1)||Abstraction is used for hiding the unwnated data and giving relevant data.||Encapsulation means hiding the code and data into single unit to prefect the data from outside world.|
|2)||Abstraction solves the problem in the design level.||Where Encapsulation solves the problem in the implementation level.|
|3)||Abstraction Examples are , Mobile Phone,||Encapsulation Examples are, Inner implementation details of a mobile phone,how kepad button and display screen are connect with each other using circuits.|
|4)||Abstraction is a OOPs concept which focuses on relevant data of an object and hides all the irrelevant details which may or may not be for generic or specialized behavior.||Encapsulation is the also OOPs concept which binds data and functions into a single component while restricting access to some components. |
|5)||It deals with ideas rather than events.||The idea is to protect the data from outside world.|
|6)||It's implemented using abstract class and interface.||It's implemented using protected, private, and package-private access modifiers.|
3) What are the advantages of OOPS concepts?
There are follwing advantages of OOPS concepts that is.
- Simplicity :- OOPS programming objects model real world objects, so the complexity is reduced and the program structure is clear.
- Modifiability :- It is easy to make small changes in the data representation . Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods.
- Maintainability :- Objects can be maintained separately,
- Reusability :- Objects can be reused in different programs.
- Modularity :- Each object forms a separate entity whose internal workings are decoupled from other parts of the system.
4) What are the core OOPS concepts ?
5) What is Abstraction?
Abstraction is an OOPS concept. Abstraction is used for hiding the unwnated data and showing the functionality.
6) What is multiple inheritance?
A child class inheriting the features that means states and behaviors from multiple parent classes is known as multiple inheritance.
7) Why Java does not support multiple inheritance?
Java doenot support multiple inheritance. suppose that C is the child class extending from both parent class A and parent class B with some methods defined in them. Then child class cannot understand which class method to call. so there is a confusion here which create to ambiguity and leads to compile time error.This is the reason java doesnot support multiple inheritance.
8) What is the meaning of "IS-A" and "HAS-A" relationship?
|NO||IS-A (Inheritance)||Has-A (Aggregationn)|
|1)||"IS-A" is also known as inheritance.||Where "HAS-A" is also known as Aggregation.|
|2)||Expressed using keyword "extends"||It is also known as "composition" or "aggregation".|
|3)||This refers to inheritance or implementation.||Has-A means an instance of one class "has a" reference to an instance of another class or another instance of same class.|
|4)||Main advantage is code reusability.||There is no specific keyword to implement HAS-A relationship but mostly we are depended upon "new" keyword.|
9) What is the difference between abstraction and encapsulation?
|1)||Abstraction is used for hiding the unwnated data and showing the functionality.||Encapsulation means hidiing the code and data into single unit to prtect the data from out side the world.|
|2)||Abstraction solves the problem in the design level.||Encapsulation solves the problem in the implementation level.|
|3)||Abstraction is implemented in Java using interface and abstract class.||Encapsulation is using private, package-private and protected access modifiers.|
|4)||By using abstraction, we can separate the things that can be grouped to another type.||Encapsulated Code is more flexible and easy to change with new requirements.|