Type Here to Get Search Results !

Top 1000 Java Interview Questions & Answers - Section II - OOPs ( Object Oriented Programming )

0


We are sharing the top 1000 Java interview questions , these questions are frequently asked by the recruiters. Java interview questions can be asked from any core java topic . So here we tried our best to provide you the java interview questions and answers for experienced which should be in your to do list before facing java questions in  technical interview. 

Java is one of the most popular programming language. There is a growing demand for Java Developer jobs in technology companies.This article contains technical interview questions that an interviewer asks for Java technology and related topics like Spring, Hibernate, Maven, Git, Microservices, AWS etc.

Each question is accompanied with an answer so that you can prepare for job interview in short time.We have compiled this list after attending dozens of technical interviews in top-notch companies like- Facebook, Amazon,Oracle, Netflix, Microsoft etc.

Once you go through them in the first pass, mark the questions that you could not answer by yourself. Then, in second pass go through only the difficult questions.

After going through this questions 2-3 times, you will be well prepared to face a technical interview for a Java Developer position from Software Engineer level to Principal Engineer level.

All the best!!

Section II - OOPS (Object Oriented Programming languages)


13. What are the main principles of Object Oriented Programming?

Main principles of Object Oriented Programming (OOPS) are:

1. Abstraction

2. Encapsulation

3. Inheritance

4. Polymorphism


 14. What is the difference between Object Oriented Programming language and Object Based Programming language?

Object Oriented Programming languages like Java and C++ follow concepts of OOPS like- Encapsulation, Abstraction, Polymorphism and Inheritance etc.

Object Based Programming languages follow some features  of OOPS but they do not provide support for Polymorphism and Inheritance. Egg. JavaScript, VBScript etc.

Object Based Programming languages provide support for Objects and you can build objects from constructor. They languages also support Encapsulation. These are also known as Prototype-oriented languages.


 15. In Java what is the default value of an object reference defined as an instance variable in an Object?

All the instance variable object references in Java are null.


 16. Why do we need constructor in Java?

Java is an object-oriented language, in which we create and use objects. A constructor is a piece of code similar to a method. It is used to create an object and set the initial state of the object.

A constructor is a special function that has same name as  class name.

Without a constructor, there is no other way to create an object.

By default, Java provides a default constructor for every object. If we overload a constructor then we have to implement default constructor.


17. Why do we need default constructor in Java classes?

Default constructor is the no-argument constructor that is automatically generated by Java if no other constructor is defined.

Java specification says that it will provide a default constructor if there is no overloaded constructor in a class. But it does not say anything about the scenario in which we write an overloaded constructor in a class.

We need at least one constructor to create an object, that’s why Java provides a default constructor.

When we have overloaded constructor, then Java assumes that we want some custom treatment in our code. Due to which it does not provide default constructor. But it needs default constructor as per the specification. So it gives error.


18. What is the value returned by Constructor in Java?

When we call a constructor in Java, it returns the object created by it. That is how we create new objects in Java.


 19. Can we inherit a Constructor?

No, Java does not support inheritance of constructor.


 20. Why constructors cannot be final, static, or abstract in Java?

If we set a method as final it means we do not want any class to override it. But the constructor (as per Java  Language Specification) cannot be overridden. So there is no use of marking it final.

If we set a method as abstract it means that it has no body and it should be implemented in a child class. But the constructor is called implicitly when the new keyword is used. Therefore it needs a body.

If we set a method as static it means that it belongs to the class, but not a particular object. The constructor is always called to initialize an object. Therefore, there is no use of marking constructor static.


Recommended Posts

Top 1000 Java Interview Questions & Answers - Section I - Java Basics

Top 1000 Java Interview Questions & Answers - Section III - Inheritance

Top 1000 Java Interview Questions & Answers - Section IV - Static

Core Java Important Questions Part 1

Core Java Important Questions Part 2

Core Java Important Questions Part 3

Core Java Important Questions Part 4

Core Java Important Questions Part 5

Core Java Important Questions Part 6

Core Java Important Questions Part 7

Core Java Important Questions Part 8

Core Java Important Questions Part 9

Java Collections Interview Questions Part 1

Java Collections Interview Questions Part 2

Java Collections Interview Questions Part 3

Java MCQs with Answers Set I

Java MCQs with Answers Set II

Java MCQs with Answers Set III

If you have any doubts join the discussion below ,our Moderator will reply to your Queries

Post a Comment

0 Comments

Top Post Ad

Below Post Ad