Describe OOP in java?

Answers were Sorted based on User's Feedback



Describe OOP in java?..

Answer / javamasque

OOP means object oriented programming, where objects play active role to fulfill request of the user. As per the OOP concept, objects have the below 4 features

Encapsulation: Objects have the ability to hide its state (properties) and behavior (methods) with the use of access modifier.

Inheritance: It is a technique to define child class / interface by extending parent class / interface. As a class implements interface is also comes under inheritance. It helps to override legacy method or abstract method with new functionality. It also facilitates the child class to access protected members of its parent.

Polymorphism: It means to overload or override the behaviors (method) of a class. There are two types of polymorphism
• Static / Compile time: To overload a method with in same class in called static or compile time polymorphism. As we call overloaded method, compiler knows which overloaded method will be called.
Example
1.Class A has two method suppose sum(int n1, int n2), sum(long n1, long n2)
2.You created instance of class A inside main method and statically called either as below
A a = new A();
a.sum1(2, 3) or a.sum(2l, 3l)
3.Hence compiler knew which overloaded method called.
• Dynamic / Run time: To override a method using inheritance is called dynamic or runtime polymorphism. Override method execution is decided at run time hence JVM can decide which override method should be called.
Example
1.Class A has a method sum() and do addition of two integers.
2.Class B is child class of A and override sum() method and do addition of two float numbers.
3.There is an another class C which has main method and inside main method we have below code snippet
A a = new B();
a.sum();
4.Now compiler knows it is method of class A will be called but at runtime the override method of class B will be called, as instance of class A will be bound with the reference of class B at runtime dynamically.
5.Hence Overriding is called dynamic or runtime polymorphism.

Is This Answer Correct ?    1 Yes 0 No

Describe OOP in java?..

Answer / javamasque

OOP means object oriented programming, where objects play active role to fulfill request of the user. As per the OOP concept, objects have the below 4 features

Encapsulation: Objects have the ability to hide its state (properties) and behavior (methods) with the use of access modifier.

Inheritance: It is a technique to define child class / interface by extending parent class / interface. As a class implements interface is also comes under inheritance. It helps to override legacy method or abstract method with new functionality. It also facilitates the child class to access protected members of its parent.

Polymorphism: It means to overload or override the behaviors (method) of a class. There are two types of polymorphism
• Static / Compile time: To overload a method with in same class in called static or compile time polymorphism. As we call overloaded method, compiler knows which overloaded method will be called.
Example
1. Class A has two method suppose sum(int n1, int n2), sum(long n1, long n2)
2. You created instance of class A inside main method and statically called either as below
A a = new A();
a.sum1(2, 3) or a.sum(2l, 3l)
3. Hence compiler knew which overloaded method called.
• Dynamic / Run time: To override a method using inheritance is called dynamic or runtime polymorphism. Override method execution is decided at run time hence JVM can decide which override method should be called.
Example
1. Class A has a method sum() and do addition of two integers.
2. Class B is child class of A and override sum() method and do addition of two float numbers.
3. There is an another class C which has main method and inside main method we have below code snippet
A a = new B();
a.sum();
4. Now compiler knows it is method of class A will be called but at runtime the override method of class B will be called, as instance of class A will be bound with the reference of class B at runtime dynamically.
5. Hence Overriding is called dynamic or runtime polymorphism.
Abstraction: Abstraction means to hide the complexity to the client. To make a class or method abstract is also a part of abstraction. The legacy and older implementations are kept in abstract class and we hide that legacy system to the client using abstraction. Suppose client is using override functionality then knowing about legacy system is of no use for client. Use of interface is also part of abstraction. If we have a fully functional DAO methods in DAO layer and we want to hide the method implementation to Service layer, then we have to use interface to provide only access of method to service layer. This way we create abstraction between DAO and service layer.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is a map? What are the implementations of map?

0 Answers  


What is return null in java?

0 Answers  


What are the advantages of encapsulation in java?

0 Answers  


What are bind parameters?

0 Answers  


What is logical variable?

0 Answers  






Can Exception handling we can handle multiple catch blocks?

0 Answers   PUCIT,


What is Classloader in Java?

0 Answers  


Explain the use of volatile field modifier?

0 Answers  


What is general methodology?

0 Answers  


2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?

0 Answers   RBS, TCS,


What is difference between static and abstract class?

0 Answers  


What is the use of accept () method in java?

0 Answers  


Categories