Interview Questions on oops Concept in Java for Freshers

What are different oops concept in java ?

OOPs stands for Object Oriented Programming. The oops concepts are similar in any other programming languages. Because it is not programming concept. All oops concept in java are;
  • Class
  • Object
  • Polymorphism
  • Inheritance
  • Abstraction
  • Encapsulation
  • Aggreagation
  • Composition
  • Association

What is class ?

A class is a specification or blue print or template of an object.

What is object ?

Object is instance of class. It is dynamic memory allocation of class.

What are the Characteristics of Object ?

Characteristics of Object are;State Behavior and Identity.

Can a class extend more than one class in Java ?

No, a class can only extend another class because Java doesn't support multiple inheritances but yes, it can implement multiple interfaces.

What is the difference between abstraction and polymorphism in Java ?

Abstraction generalizes the concept and Polymorphism allow you to use different implementation without changing your code.

What is an Abstraction ?

Abstraction is a process to show only usful data and remaining hide from user.

Real Life Example of Abstraction ?

When you log into your email, compose and send a mail. Again there is a whole lot of background processing involved, verifying the recipient, sending request to the email server, sending your email. Here you are only interested in composing and clicking on the send button. What really happens when you click on the send button, is hidden from you.

Real life example of abstraction ?

Real life example of abstraction is ATM machine; here only show balance in your account but not display ATM pin code.

What is Encapsulation ?

The process of binding data and methods into a single unit is known as Encapsulation. In other word The process of binding the data with related methods known as encapsulation.

Real Life Example of Encapsulation ?

Encapsulation is like enclosing in a capsule. 
Encapsulation is like your bag in which you can keep your pen, book etc.

What is inheritance ?

It is used in java for achieve concept of re-usability. As the name suggests , inheritance means to take something that already made.

What is polymorphism ?

It is process to represent any things in multiple forms.

Real life example of Polymorphism ?

A Person who knows more than two languages he can speak in a language which he knows. Here person is Object and speak is polymorphisam.

What is method overloading in Java ?

When same method is available in any class with same name and different signature is called method overloading.

What is method overriding in Java ?

When same method available in base class and drive class with same name and same signature it is called method overriding.

What is Aggregation ?

If a class have an entity reference, it is known as Aggregation. Aggregation represents HAS-A relationship..

What is Composition ?

Composition is the design technique to implement has-a relationship in classes. Composition in java is achieved by using instance variables that refers to other objects.

Can we declare abstract method as final ?

No. its not possible to declare abstract method with final keyword. Because abstract methods should be override by its sub classes.

Is it possible to declare abstract method as private ?

No. its not possible to declare abstract method with private. Because abstract methods should be override by its sub classes.

Differences between method Overloading and method Overriding ?

Overloaded MethodOverridden Method
ArgumentsMust be ChangeMust not be change
Return TypeCan changeCan't change except for covariant returns
ExceptionsCan ChangeCan reduce or eliminate. Must not throw new or broader checked exceptions
AccessCan changeMust not make more restrictive (can be less restrictive)
InvocationReference type determines which overloaded version is selected. Happens at compile time.Object type determines which method is selected. Happens at runtime.

Related

Interview Questions 7960104658915762161

Post a Comment

emo-but-icon

item