Skip to main content

OOPs Interview Question in Java





Most Frequently asked Interview Questions and Answer in Java:



           In this Java Interview Question blog, we have covered almost total 100+ important all OOPs concepts interview questions and answer in java for freshers and experienced candidates one by one topics.


Method Overloading and Overriding Interview Questions
Polymorphism Interview Questions in Java
Abstraction Interview Questions in Java


            This post on JAVA Interview Questions and Answers is prepared to help you understand the basic concepts of Java programming for top composes interview purposes. All the most important JAVA concepts are explained here with examples for your easy understanding.

             This blog covers core JAVA topics, advance java topics and also industry level project related most important Interview Questions with examples to make you get ready perfectly to face any JAVA interview confidently.

basic Java Interview Question and Answer,
OOPs concepts Interview Question and Answer,
Collections Interview Question and Answer,
Exception Handling Interview Question and Answer,
Multi-threading Interview Question and Answer,
Serialization and Deserialization Interview Question and Answer,
Keywords Interview Questions and Answer --------- Static keyword and Final Keyword


Most Popular Java Interview Questions:


          Given below is a comprehensive list of most important and commonly asked about OOPs Concept  basic and advanced Java programming interview questions with detailed answers.





1.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



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

           Object Oriented Programming languages like C++ and  Java 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 Inheritance and Polymorphism. Egg. JavaScript, VBScript etc. Object Based Programming languages provide support for Objects and you can also build objects from constructor. They languages also support Encapsulation. These are also known as Prototype-oriented languages.


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

         All the instance variable object references in Java are null.


4.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.


5.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.


6.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.


7.Can we inherit a Constructor?

        No, Java does not support inheritance of constructor.


8. 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.








Comments

Popular posts from this blog

DOCKER Interview questions

DOCKER 1. What is Docker? Docker is Open Source software. It provides the automation of Linux application deployment in a software container. We can do operating system level virtualization on Linux with Docker. Docker can package software in a complete file system that contains software code, runtime environment, system tools, & libraries that are required to install and run the software on a server. 2. What is the difference between Docker image and Docker container? Docker container is simply an instance of Docker image. A Docker image is an immutable file, which is a snapshot of container. We create an image with build command. When we use run command, an Image will produce a container. In programming language, an Image is a Class and a Container is an instance of the class. 3. How will you remove an image from Docker? We can use docker rmi command to delete an image from our local system. Exact command is: % docker rmi <Image Id> If we want to fin

Cloud Computing Interview Questions

Cloud Computing 1. What are the benefits of Cloud Computing? There are ten main benefits of Cloud Computing: Flexibility : The businesses that have fluctuating bandwidth demands need the flexibility of Cloud Computing. If you need high bandwidth, you can scale up your cloud capacity. When you do not need high bandwidth, you can just scale down. There is no need to be tied into an inflexible fixed capacity infrastructure. Disaster Recovery : Cloud Computing provides robust backup and recovery solutions that are hosted in cloud. Due to this there is no need to spend extra resources on homegrown disaster recovery. It also saves time in setting up disaster recovery. Automatic Software Updates : Most of the Cloud providers give automatic software updates. This reduces the extra task of installing new software version and always catching up with the latest software installs. Low Capital Expenditure : In Cloud computing the model is Pay as you Go. This means there is very

Microservices Interview Questions

Microservices Interview Questions 1. What is a Microservice in Java? A Microservice is a small and autonomous piece of code that does one thing very well. It is focused on doing well one specific task in a big system. It is also an autonomous entity that can be designed, developed and deployed independently. Generally, it is implemented as a REST service on HTTP protocol, with technology-agnostic APIs. Ideally, it does not share database with any other service. 2. What are the benefits of Microservices architecture? Microservices provide many benefits. Some of the key benefits are: 1.      Scaling : Since there are multiple Microservices instead of one monolith, it is easier to scale up the service that is being used more. Eg. Let say, you have a Product Lookup service and Product Buy service. The frequency of Product Lookup is much higher than Product Buy service. In this case, you can just scale up the Product Lookup service to run on powerful hardware with multipl