preloader

All theoretical questions from OOP Concept are covered with answers

OOP Concept Interview

  • COURSES

    04 Month

  • DURATION

    03 Hours

Explain OOPs concept in java?

Object Oriented Programming is concept of handling object in different ways ,
There are four pillars of OOPS concept:

  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
  • Class
  • Object

Inheritance

Inheritance is mechanism to acquire property and behaviour of parent object to its child .
“extends” keyword is used for implementation of inheritance.
Inheritance represents the IS-A relationship which is also known as a parent-child relationship.

Need of Inheritance
  • for code reusability
  • For method overriding

Why multiple inheritance is not supported in java?

To avoid method ambiguity java does not support multiple inheritance. Since, Every child class extend parent property when JVM call parent property ,but it will confused which parent property will be acquired .

Polymorphism

“Poly” means many and “Morphs” means forms .
When a Object achieve multiple property or forms according to its requirement , it is known as Polymorphism
ex: Myself on home behaves as part of family where as Myself in office as senior software engineer behaves as part of Organisation

There are two types of Polymorphism
  • Compiletime Polymorphism
  • Runtime Polymorphism
Compiletime Polymorphism Runtime Polymorphism
when object is binded at compile time with functionality ,it is known as Compiletime Polymorphism whenever object is binded at runtime with functionality , it is known as Runtime Polymorphism
it is also known as Early binding or Static binding it is also known as late binding or dynamic binding
it can be achieved through Method Overloading it can be achieved through Method Overriding
it does not require inheritance it require inheritance

Difference between Method Overloading vs Method Overriding

  • Method Overloading
  • Method Overriding
Method Overloading Method Overriding
in method Overloading method name must be same and signature or Parameter must be different either no of parameter or name of parameter Method Overriding method name, parameter and return type must be same only implementation will be changed
Inheritance is not required Inheritance is required
return type may be same or different return type must be same
perform at compiletime only perform at runtime only

Can main method can be overloaded or overridden?

The main method can be overloaded but cannot be overridden in Java. when we overload main method , JVM still run original method ,it will never call our overloaded main method.
overriding is not happening in the case of main method as it is static method which is independent of object creation and overriding is binding of object only

Can we Override private or Static method?

No, we can not override any static method as it belong to class level initialization rather then object level.

Abstraction

Hiding the implementation showing only the functionality to the user is known as Abstraction. Abstraction solve problem at design level.
ex: Television
it can be achieved by interface and abstract class.

Abstract class Interface
Abstract class can have both abstract and non-abstract method Interface can have only abstract method
Non static and Non final variable are also allowed Only Static and Final variable are allowed
does not support multiple inheritance support multiple inheritance
Abstract class can be extended interface can be implemented
Data member are private and protected Data member are public only

Encapsulation

Encapsulation is wrapping data and code together in a single unit .it is used for data hiding purposes . it can be achieved through getter an setter method Java Bean Class is best example of it. it solve the problem on implementation level.

Define Association in java

Association is connection between two classes that are set up through their objects .
There are different types of association

  • IS- A association
  • HAS-A association

Define Aggregation and Composition

Aggregation Composition
Linked objects are independent of each other Linked objects are tightly coupled or dependent on each other
if we delete the parent object, the child object will still exist in the system. if delete the parent object the child object also gets delete .
ex: car and tyres are aggregation relationship if we remove tyre also car will function. ex: folders and files are composition if we delete folder files also get deleted.
denoted as empty diamond denotes as filled diamond
weak type of association Strong type of association

Related Course

course thumb

Basic Java

All basic level question for java covered in this section for any one either experienced or fresher

Visit
course thumb

Multithreading

All multi-threading level questions such as thread ,process,synchronization ,join,thread priorities covered.

Visit
course thumb

Exception handling

Exception handling ,it type ,error vs Exception

Visit